home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / TPointMatrix.cp < prev    next >
Encoding:
Text File  |  1992-02-21  |  96.3 KB  |  2,955 lines  |  [TEXT/MPS ]

  1. #pragma segment Matrix
  2. // **********************************************************************
  3. //    TPointMatrix Class
  4. //        Contains a list of grid rows (list of TGridRow).
  5. //        Each row contains a list of points (list of TPoint).
  6. //        This class is responsible for managing the point information in the geometry.
  7. //        including creating new points, draggin, obstacles etc.
  8. // **********************************************************************
  9. // --------------------------------------------------------------------------------------------------
  10. //    TPointMatrix    :    Initialize the Class
  11. // --------------------------------------------------------------------------------------------------
  12. Boolean TPointMatrix::IPointMatrix(TDocument * tDocument, TView * tGeom)    
  13.     {
  14.     TCornorPoint     *    nCPt1, * nCPt2, * nCPt3, * nCPt4, * nCPt5;        // new cornor point
  15.     TRow                *    tRow;                                                                    // new row of points
  16.     
  17.     fDocument    = tDocument;                                                                // store the document pointer
  18.     fGeomView    = tGeom;                                                                        // store the geomview pointer
  19.     inherited::IList();                                                                                // create the list
  20.  
  21. //    Create the points
  22.     nCPt1 = new TCornorPoint;                                                            // allocate space for point object
  23.         FailNIL(nCPt1);                                                                            // LAM
  24.     nCPt1->IPoint(0, 0, Wall,true,((TGeomView *) fGeomView)->fMagnify);// initialize Cornor Point
  25.  
  26.     nCPt2 = new TCornorPoint;                                                            // allocate space for point object
  27.         FailNIL(nCPt2);                                                                            // LAM
  28.     nCPt2->IPoint(0, 0, Wall,true,((TGeomView *) fGeomView)->fMagnify);    // initialize Cornor Point
  29.  
  30.     nCPt3 = new TCornorPoint;                                                            // allocate space for point object
  31.         FailNIL(nCPt3);                                                                            // LAM
  32.     nCPt3->IPoint(0, 0, Wall,true,((TGeomView *) fGeomView)->fMagnify);        // initialize Cornor Point
  33.  
  34.     nCPt4 = new TCornorPoint;                                                            // allocate space for point object
  35.         FailNIL(nCPt4);                                                                            // LAM
  36.     nCPt4->IPoint(0, 0, Wall,true,((TGeomView *) fGeomView)->fMagnify);    // initialize Cornor Point
  37.  
  38.     nCPt5 = new TCornorPoint;                                                            // allocate space for point object
  39.         FailNIL(nCPt5);                                                                            // LAM
  40.     nCPt5->IPoint(0, 0, Wall,true,((TGeomView *) fGeomView)->fMagnify);    // initialize Cornor Point
  41.  
  42.     tRow = new TRow;                                                                        // allocate space for the new row
  43.         FailNIL(tRow);                                                                            // LAM
  44.     tRow->IRow(nCPt1,nCPt2);                                                            // initialize the row
  45.     this->InsertFirst((TObject *) tRow);                                            // insert the row
  46.     
  47.     tRow = new TRow;                                                                        // allocate space for the new row
  48.         FailNIL(tRow);                                                                            // LAM
  49.     tRow->IRow(nCPt3,nCPt4);                                                            // initialize the row
  50.     this->InsertLast((TObject *) tRow);                                                // insert the row
  51.     
  52.     aColumn = new TList;
  53.     aColumn->IList();
  54.     
  55.     fTop            = new TBoundry;
  56.         FailNIL(fTop);
  57.     fBottom    = new TBoundry;
  58.         FailNIL(fBottom);
  59.     fLeft            = new TBoundry;
  60.         FailNIL(fLeft);
  61.     fRight        = new TBoundry;
  62.         FailNIL(fRight);
  63.         
  64.     fTop->IRow(nCPt1,nCPt2,cTop);
  65.     fBottom->IRow(nCPt3,nCPt4,cBottom);
  66.     fLeft->IRow(nCPt1,nCPt3,cLeft);
  67.     fRight->IRow(nCPt2,nCPt5,cRight);
  68.         
  69.     fBoundry    = cTop;
  70.     fShown        = true;
  71.     fFineGrid    = false;
  72.     fRow        = fColumn = 1;
  73.     return true;
  74.     }
  75.  
  76. // --------------------------------------------------------------------------------------------------
  77. //    TPointMatrix    :    GetCurrentBoundry
  78. //        returns the boundry object for the current boundry
  79. // --------------------------------------------------------------------------------------------------
  80. void TPointMatrix::InitCorners(void)    
  81.     {
  82.     Point    ul, ur, ll, lr;
  83.     TCornorPoint     *    nCPt1;                                                                // new cornor point
  84.  
  85. //    Find the cornor points of the initial geometry.  This geometry is a rectangle.
  86. //    It's size is based on the size entered by the used in the dimensions dialog.
  87.     ul.v    =    cGeomViewBorder;
  88.     ul.h     =     cGeomViewBorder;
  89.     ur.v    =     cGeomViewBorder;
  90.     ll.h     =     cGeomViewBorder;
  91.     ur.h    =    ((TGeomView *) fGeomView)->GetHorizViewSize() + cGeomViewBorder;
  92.     ll.v    =    ((TGeomView *) fGeomView)->GetVertViewSize() + cGeomViewBorder;
  93.     lr.v    =    ((TGeomView *) fGeomView)->GetVertViewSize() + cGeomViewBorder;
  94.     lr.h    =    ((TGeomView *) fGeomView)->GetHorizViewSize() + cGeomViewBorder;
  95.  
  96. //    Create the points
  97.     nCPt1 = (TCornorPoint *) fTop->First();                                        // get point
  98.         FailNIL(nCPt1);                                                                            // LAM
  99.     nCPt1->SetStart(ul.v, ul.h);                                                            // initialize Cornor Point
  100.  
  101.     nCPt1 = (TCornorPoint *) fTop->Last();                                        // get point
  102.         FailNIL(nCPt1);                                                                            // LAM
  103.     nCPt1->SetStart(ur.v, ur.h);                                                        // initialize Cornor Point
  104.  
  105.     nCPt1 = (TCornorPoint *) fBottom->First();                                    // get point
  106.         FailNIL(nCPt1);                                                                            // LAM
  107.     nCPt1->SetStart(ll.v, ll.h);                                                            // initialize Cornor Point
  108.  
  109.     nCPt1 = (TCornorPoint *) fBottom->Last();                                    // get point
  110.         FailNIL(nCPt1);                                                                            // LAM
  111.     nCPt1->SetStart(lr.v, lr.h);                                                            // initialize Cornor Point
  112.  
  113.     nCPt1 = (TCornorPoint *) fRight->Last();                                        // get point
  114.         FailNIL(nCPt1);                                                                            // LAM
  115.     nCPt1->SetStart(lr.v, lr.h);                                                            // initialize Cornor Point
  116.     }
  117.  
  118. // --------------------------------------------------------------------------------------------------
  119. //    TPointMatrix    :    Free
  120. //        returns the boundry object for the current boundry
  121. // --------------------------------------------------------------------------------------------------
  122. pascal void TPointMatrix::Free(void)    
  123.     {
  124.     short     i,ii;
  125.     TRow     * tRow;
  126.     TPoint    * tPt;
  127.     for (ii = (short) this->fSize; ii > 0; ii--)
  128.         {
  129.         tRow = (TRow *) this->At(ii);
  130.         for (i = (short) tRow->fSize; i > 0; i--)
  131.             {
  132.             tPt = (TPoint *) tRow->At(i);
  133.             if (tPt->fObsUpLeft != NULL)
  134.                 FreeIfObject(tPt->fObsUpLeft);
  135.             if (tPt->fBaffAbove != NULL)
  136.                 FreeIfObject(tPt->fBaffAbove);
  137.             if (tPt->fBaffLeft != NULL)
  138.                 FreeIfObject(tPt->fBaffLeft);
  139.             
  140.             tRow->Delete(tPt);
  141.             FreeIfObject(tPt);
  142.             }
  143.         this->Delete(tRow);
  144.         FreeIfObject(tRow);
  145.         }
  146.     FreeIfObject(aColumn);
  147.     inherited::Free(); 
  148.     return;
  149.     }
  150.     
  151. // --------------------------------------------------------------------------------------------------
  152. //    TPointMatrix    :    GetCurrentBoundry
  153. //        returns the boundry object for the current boundry
  154. // --------------------------------------------------------------------------------------------------
  155. TRow * TPointMatrix::GetCurrentBoundry(void)    
  156.     {
  157.     switch (fBoundry)
  158.         {
  159.         case cTop:
  160.             return fTop;
  161.         case cBottom:
  162.             return fBottom;
  163.         case cLeft:
  164.             return fLeft;
  165.         case cRight:
  166.             return fRight;
  167.         }
  168.     return NULL;
  169.     }
  170.     
  171. // --------------------------------------------------------------------------------------------------
  172. //    TPointMatrix    :    GetOpposite
  173. //        returns the boundry object for the current boundry
  174. // --------------------------------------------------------------------------------------------------
  175. TPoint * TPointMatrix::GetOpposite(TBoundry * side, short row, short column)    
  176.     {
  177.     short        s, i;
  178.     TBoundry    * ss;
  179.     
  180.     s = side->GetSide();
  181.     switch (s)
  182.         {
  183.         case cTop:
  184.             i    = column;
  185.             ss = fBottom;
  186.             break;
  187.         case cBottom:
  188.             i    = column;
  189.             ss = fTop;
  190.             break;
  191.         case cLeft:
  192.             i    = row;
  193.             ss = fRight;
  194.             break;
  195.         case cRight:
  196.             i    = row;
  197.             ss = fLeft;
  198.             break;
  199.         }
  200.     return (TPoint *) ss->At(i);
  201.     }
  202.     
  203. // --------------------------------------------------------------------------------------------------
  204. //    TPointMatrix    :    GetTColumn .... 
  205. //        returns the number of columns in the grid
  206. // --------------------------------------------------------------------------------------------------
  207. short TPointMatrix::GetTColumn(void)
  208.     {
  209.     TRow * tRow;
  210.     tRow = (TRow *) this->First();
  211.     return ((short) tRow->fSize);
  212.     }
  213.     
  214. // --------------------------------------------------------------------------------------------------
  215. //    TPointMatrix    :    GetNumBaffle .... 
  216. //        returns the number of baffles in the grid
  217. // --------------------------------------------------------------------------------------------------
  218. short TPointMatrix::GetNumBaffle(Boolean vert)
  219.     {
  220.     TRow     * tRow;
  221.     short     i, total;
  222.     
  223.     total = 0;
  224.     for (i = 1; i <= (short) fSize; i++)
  225.         {
  226.         tRow = (TRow *) this->At(i);
  227.         total += tRow->GetNumBaffle(vert);
  228.         }
  229.     return total;
  230.     }
  231.     
  232. // --------------------------------------------------------------------------------------------------
  233. //    TPointMatrix    :    GetNumBaffle .... 
  234. //        returns the number of baffles in the grid
  235. // --------------------------------------------------------------------------------------------------
  236. short TPointMatrix::GetNumObstacle(void)
  237.     {
  238.     TRow     * tRow;
  239.     short     i, total;
  240.     
  241.     total = 0;
  242.     for (i = 1; i <= (short) fSize; i++)
  243.         {
  244.         tRow = (TRow *) this->At(i);
  245.         total += tRow->GetNumObstacle();
  246.         }
  247.     return total;
  248.     }
  249.     
  250. // --------------------------------------------------------------------------------------------------
  251. //    TPointMatrix    :    GetCurrent .... 
  252. //        returns the current point described by fRow & fColumn
  253. // --------------------------------------------------------------------------------------------------
  254. TPoint * TPointMatrix::GetCurrent(void)
  255.     {
  256.     TRow * tRow;
  257.     if (fRow <= fSize)
  258.         tRow = (TRow *) this->At(fRow);
  259.     if (fColumn <= (short) tRow->fSize)
  260.         return ((TPoint *) tRow->At(fColumn));
  261.     return NULL;
  262.     }
  263.     
  264. // --------------------------------------------------------------------------------------------------
  265. //    TPointMatrix    :    SetCurrent .... 
  266. //        sets fRow & fColumn to the point passed in
  267. // --------------------------------------------------------------------------------------------------
  268. short TPointMatrix::SetCurrent(TPoint * tPt)
  269.     {
  270.     short x,y;
  271.     TRow    * tRow;
  272.     TPoint    * t;
  273.     
  274.     t = (TPoint *) fRight->Last();                                                        // check lower right corner
  275.     if (t == tPt)
  276.         {
  277.         fColumn    = (short) fBottom->fSize;
  278.         fRow        = (short) fRight->fSize;
  279.         return 0;
  280.         }
  281.         
  282.     for (y=1; y<= (short) fSize; y++)
  283.         {
  284.         tRow = (TRow *) this->At(y);
  285.         if ((x = (short) tRow->GetSameItemNo((TObject *) tPt)) !=  0)
  286.             {
  287.             fRow = y;
  288.             fColumn = x;
  289.             if (fRow == 1)
  290.                 fBoundry = cTop;
  291.             else if (fRow == (short) this->fSize)
  292.                 fBoundry = cBottom;
  293.             else if (fColumn == 1)
  294.                 fBoundry = cLeft;
  295.             else if (fColumn == (short) ((TRow *) this->At(fRow))->fSize)
  296.                 fBoundry = cRight;
  297.             return 0;
  298.             }
  299.         }
  300.     return 1;
  301.     }
  302.     
  303. // --------------------------------------------------------------------------------------------------
  304. //    TPointMatrix    :    SetCornors .... 
  305. //        places the surrounding points in the PointInfo structure
  306. // --------------------------------------------------------------------------------------------------
  307. short TPointMatrix::SetCornors(TPoint * tPt, PointInfo * info)
  308.     {
  309.     TRow *    tRow;
  310.     if (this->SetCurrent(tPt) == 1)                                                        // set fRow/fColumn to this point
  311.         return 1;
  312.     
  313.     info->left = info->right = info->above = info->below = info->oPt = NULL;
  314.     info->aboveRow = info->belowRow = NULL;
  315.     
  316.     info->row = fRow;                                                                        // current row
  317.     info->column = fColumn;                                                                // current column
  318.     info->gridOnly = !fShown;                                                                // assign opposite of fShown
  319.     info->lrc = NULL;
  320.     
  321.     if (tPt->IsBoundryPt())                                                                    // only load boundry
  322.         {
  323.         TBoundry * side;
  324.         side = (TBoundry *) this->GetCurrentBoundry();
  325.         info->boundry = fBoundry;
  326.         if (tPt->IsCornor())                                                                    // point is on a cornor
  327.             {
  328.             if (fRow == 1 && fColumn == 1)                                            // upper left cornor
  329.                 {
  330.                 info->left        = (TPoint *) fLeft->At(2);
  331.                 info->right    = (TPoint *) fTop->At(2);
  332.                 info->dLeft    = info->dRight = true;
  333.                 return 0;
  334.                 }
  335.             if (fRow == 1 && fColumn == (short) fTop->fSize)                // upper right cornor
  336.                 {
  337.                 info->left        = (TPoint *) fTop->At((fTop->fSize) - 1);
  338.                 info->right    = (TPoint *) fRight->At(2);
  339.                 info->dLeft    = false;
  340.                 info->dRight    = true;
  341.                 return 0;
  342.                 }
  343.             if (fRow == (short) fSize && fColumn == (short) fBottom->fSize) // lower right cornor
  344.                 {
  345.                 info->left        = (TPoint *) fRight->At((fRight->fSize) - 1);
  346.                 info->right    = (TPoint *) fBottom->At((fBottom->fSize)-1);
  347.                 info->lrc        = (TPoint *) fRight->Last();
  348.                 info->dLeft    = false;
  349.                 info->dRight    = false;
  350.                 return 0;
  351.                 }
  352.             info->left        = (TPoint *) fBottom->At(2);                            // lower left cornor
  353.             info->right    = (TPoint *) fLeft->At((fLeft->fSize)-1);
  354.             info->dLeft    = true;
  355.             info->dRight    = false;
  356.             return 0;
  357.             }
  358.             
  359.         tRow = (TRow *) this->At(fRow);                                                // get current row
  360.         if (fBoundry == cLeft || fBoundry == cRight)
  361.             {
  362.             info->left        = (TPoint *) side->At(fRow - 1);                        // get boundry points on
  363.             info->right    = (TPoint *)  side->At(fRow + 1);                        //   either side of current
  364.             if (fShown)                                                                            // is grid on?
  365.                 {                                                                                        // get grid points
  366.                 if (fBoundry == cLeft)                                                        // left boundry
  367.                     info->above = (TPoint *) tRow->At(2);
  368.                 else                                                                                    // right boundry
  369.                     info->above = (TPoint *) tRow->At((tRow->fSize) - 1);
  370.                 }
  371.             return 0;
  372.             }
  373.         else                                                                                            // top & bottom boundry
  374.             {
  375.             info->left        =    (TPoint *) side->At(fColumn - 1);                    // get boundry points on
  376.             info->right    =    (TPoint *) side->At(fColumn + 1);                // either side of current
  377.             if (fShown)                                                                            // is grid on?
  378.                 {
  379.                 if (fBoundry == cTop)                                                        // get grid points
  380.                     info->above    =    (TPoint *) ((TRow *) this->At(2))->At(fColumn); // top boundry
  381.                 else                                                                                    // bottom boundry
  382.                     info->above    =    (TPoint *) ((TRow *) this->At((short) fSize - 1))->At(fColumn);
  383.                 }
  384.             return 0;
  385.             }
  386.         }
  387.  
  388.     if (!fShown)                                                                                    // no grid 
  389.         return 1;
  390.  
  391. //    grid is on so load grid points too.        
  392.     tRow = (TRow *) this->At(fRow);                                                    // get current row
  393.     info->left = (TPoint *) tRow->At(fColumn - 1);                                // point to the left of this
  394.     info->right = (TPoint *) tRow->At(fColumn + 1);                            // point to the left    
  395.     info->aboveRow = (TRow *) this->At(fRow - 1);                            // row above current
  396.     info->above = (TPoint *) (info->aboveRow)->At(fColumn);            // point above current
  397.     info->belowRow = (TRow *) this->At(fRow + 1);                            // get next row
  398.     info->below = (TPoint *) (info->belowRow)->At(fColumn);            // point below current
  399.     return 0;
  400.     }
  401.     
  402. // *********************************************************************************
  403. //    Drawing Methods
  404. // *********************************************************************************
  405. // --------------------------------------------------------------------------------------------------
  406. //    TPointMatrix    :    Draw
  407. //        Draws the points, segment lines & grid lines
  408. // --------------------------------------------------------------------------------------------------
  409. void TPointMatrix::DoDraw(void)    
  410.     {
  411.     PointInfo info;
  412.     
  413.     info.gridOnly = false;
  414.     info.noGrid    = fShown;
  415.     info.magnify    = ((TGeomView *) fGeomView)->fMagnify;
  416.     info.lrc = NULL;
  417.     HLock((Handle) this);
  418.     if (fShown)
  419.         {
  420.         this->Each(DrawAllLines,&info);
  421.         this->Each(DrawAllPoints,&info);
  422.         }
  423.     else
  424.         {
  425.         info.boundry = cTop;                                                                                            // top boundry
  426.         this->TBBoundryDo(DrawAllLines,&info);
  427.         this->TBBoundryDo(DrawAllPoints,&info);
  428.         info.boundry = cBottom;                                                                                    // bottom boundry
  429.         this->TBBoundryDo(DrawAllLines,&info);
  430.         this->TBBoundryDo(DrawAllPoints,&info);
  431.  
  432.         info.boundry = cRight;                                                                                        // right boundry
  433.         this->RLBoundryDo(DrawLine,&info);
  434.         this->RLBoundryDo(DrawPoint,&info);
  435.         info.boundry = cLeft;                                                                                        // left boundry
  436.         this->RLBoundryDo(DrawLine,&info);
  437.         this->RLBoundryDo(DrawPoint,&info);
  438.         }
  439.     HUnlock((Handle) this);
  440.  
  441.     if (fFineGrid)
  442.         this->ShowFineGrid();
  443.     if (((TGeomView *) fGeomView)->fSPoint != NULL)
  444.         this->DoHighlight();
  445.     }
  446.     
  447. // --------------------------------------------------------------------------------------------------
  448. //    TPointMatrix    :    Draw
  449. //        Draws the points & grid lines
  450. // --------------------------------------------------------------------------------------------------
  451. void TPointMatrix::DoDrawGrid(void)    
  452.     {        
  453.     PointInfo info;
  454.     
  455.     fGeomView->Focus();
  456.     info.gridOnly = true;
  457.     info.noGrid    =    fShown;
  458.     info.magnify    = ((TGeomView *) fGeomView)->fMagnify;
  459.     HLock((Handle) this);
  460.     this->Each(DrawAllLines,&info);
  461.     this->Each(DrawAllPoints,&info);
  462.     HUnlock((Handle) this);
  463.     
  464.     fShown = !fShown;
  465.     }
  466.     
  467. // --------------------------------------------------------------------------------------------------
  468. //    TPointMatrix    :    DrawSegment .... 
  469. //        draws each section in this segment
  470. // --------------------------------------------------------------------------------------------------
  471. void  TPointMatrix::DoDrawSegment(void)
  472.     {
  473.     short         index;                                                                        // counter
  474.     TRow     *    side;                                                                            // the side the boundry is on
  475.     Point        pt;
  476.     TPoint    *    tPt1, * tPt2;                                                            // the point
  477.  
  478.     side     = ((TGeomView *) fGeomView)->fSSide;
  479.     this->SetCurrent (((TGeomView *) fGeomView)->fSPoint);
  480.     
  481.     if (side->GetSide() == cTop  || side->GetSide() == cBottom)
  482.         index = fColumn;
  483.     else
  484.         index = fRow;
  485.         
  486.     while (index > 1)                                                                        // do until previous segment
  487.         {
  488.         tPt1 = (TPoint *) side->At(index);
  489.         tPt2 = (TPoint *) side->At(index-1);
  490.         
  491.         pt = tPt2->fTrans;
  492.         tPt1->DrawSection(pt);
  493.         tPt1->Draw();
  494.  
  495.         if (tPt2->IsSegment())
  496.             break;
  497.         index--;
  498.         }
  499.  
  500.     tPt2->Draw();
  501.     return;
  502.     }
  503.  
  504. // --------------------------------------------------------------------------------------------------
  505. //    TPointMatrix    :    Highlight .... 
  506. //        highlights the point or the segment
  507. // -------------------------------------------------------------------------------------------------
  508. void  TPointMatrix::DoHighlight(void)
  509.     {
  510.     if (((TGeomView *) fGeomView)->fSPoint ==NULL)
  511.         return;
  512.         
  513.     fGeomView->Focus();
  514.     if (!((TGeomView *) fGeomView)->fSegment)
  515.         {
  516.         Point t;
  517.         t = ((TGeomView *) fGeomView)->fSPoint->fStart;
  518.         ((TGeomView *) fGeomView)->fSPoint->Highlight();                // highlight only the point
  519.         return;
  520.         }
  521.  
  522.     short         index;                                                                        // counter
  523.     TRow     *    side;                                                                            // the side the boundry is on
  524.     Point        pt;
  525.     TPoint    *    tPt1, * tPt2;                                                            // the point
  526.  
  527.     side     = ((TGeomView *) fGeomView)->fSSide;
  528.     this->SetCurrent (((TGeomView *) fGeomView)->fSPoint);
  529.  
  530.     if (side->GetSide() == cTop  || side->GetSide() == cBottom)
  531.         index = fColumn;
  532.     else
  533.         index = fRow;
  534.         
  535.     while (index > 1)                                                                        // do until previous segment
  536.         {
  537.         tPt1 = (TPoint *) side->At(index);
  538.         tPt2 = (TPoint *) side->At(index-1);
  539.         
  540.         tPt1->Highlight();
  541.         pt = tPt2->fTrans;
  542.         tPt1->HighlightSection(pt);
  543.  
  544.         if (!tPt2->IsSelected())
  545.             break;
  546.         index--;
  547.         }
  548.  
  549.     tPt2->Highlight();
  550.     return;
  551.     }
  552.     
  553. // --------------------------------------------------------------------------------------------------
  554. //    TPointMatrix    :    ShowFineGrid .... 
  555. //        Displays the fine grid
  556. // -------------------------------------------------------------------------------------------------
  557. void  TPointMatrix::ShowFineGrid(void)
  558.     {
  559. //
  560. //    draw the fine grid lines.
  561. //    draw all the fine rows from bottom right corner to top left corner
  562. //    then draw all the fine columns from bottom right corner to top left corner
  563. //                Point / Row Order: 
  564. //    Row 2            4    â€¢                3    â€¢
  565. //            
  566. //
  567. //    Row 1            2    â€¢                1    â€¢
  568. //
  569.     lineSlope    line1, line2;
  570.     short         gridLines;
  571.     short        xx, yy, i, temp;
  572.     TRow        * tR1, * tR2;
  573.     TPoint        * tPt;
  574.     Point        pt1[16], pt2[16];
  575.     extended    interval1, interval2, dist1, dist2;
  576.     
  577.     temp = (short) ((TCFDFrontDocument *) fDocument)->GetFineGrid();
  578.     gridLines = (short) pow(2,(temp-1));
  579.     if (gridLines == 1)
  580.         return;
  581.         
  582.     fGeomView->Focus();
  583.     PenMode(srcXor);
  584.     RGBForeColor(&FineGridColor);                                                        // forground color.
  585.     PenPixPat(FineGridPat);
  586.     PenSize (gGridsize_H, gGridsize_V);                                                    // set pensize
  587.  
  588. //    horizontal fine grid lines
  589.     tR2 = (TRow *) this->Last();                                                            // get the bottom row
  590.     for (yy = (short) this->fSize-1; yy > 0; yy--)
  591.         {
  592.         tR1 = tR2;                                                                                    // assign tr1 to previous tr2
  593.         tR2 = (TRow *) this->At(yy);                                                        // get row above tr1
  594.         
  595.         line1.first        = ((TPoint *) tR1->Last())->fTrans;
  596.         line1.second    = ((TPoint *) tR2->Last())->fTrans;
  597.         HLock((Handle) this);
  598.         SlopeIntercept(&line1);
  599.         dist1 = CalculateDistance(line1.first, line1.second);                        // get length of cell segments
  600.         interval1 = dist1 / gridLines;
  601.         
  602.         this->CalculateFinePt(&line1, gridLines, interval1, pt1);
  603.         HUnlock((Handle) this);
  604.         
  605.         for (xx = (short) tR1->fSize-1; xx > 0; xx--)                                // do all points in the row
  606.             {
  607.             tPt                = (TPoint *) tR1->At(xx+1);
  608.             line2.first        = ((TPoint *) tR1->At(xx))->fTrans;
  609.             line2.second    = ((TPoint *) tR2->At(xx))->fTrans;
  610.             HLock((Handle) this);
  611.             SlopeIntercept(&line2);
  612.             dist2 = CalculateDistance(line2.first, line2.second);
  613.             interval2 = dist2 / gridLines;                                                        // length of each sub-cell
  614.             
  615.             this->CalculateFinePt(&line2, gridLines, interval2, pt2);
  616.             HUnlock((Handle) this);
  617.             for (i = 0; i < gridLines-1; i++)
  618.                 {
  619.                 if (tPt->fObsUpLeft == NULL)
  620.                     {
  621.                     MoveTo(pt1[i].h+1,pt1[i].v+1);                                                // move to provided point
  622.                     LineTo (pt2[i].h+1, pt2[i].v+1);                                                // draw to this point
  623.                     }
  624.                 pt1[i].h = pt2[i].h; 
  625.                 pt1[i].v = pt2[i].v;  
  626.                 }
  627.             }
  628.         }
  629.  
  630. //    vertical fine grid lines
  631.     for (xx = (short) tR1->fSize-1; xx > 0; xx--)                                    // do all points in the row
  632.         {
  633.         tR2 = (TRow *) this->Last();                                                        // get the bottom row
  634.         tR1 = tR2;                                                                                    // assign tr1 to previous tr2
  635.         
  636.         line1.first        = ((TPoint *) tR1->At(xx+1))->fTrans;
  637.         line1.second    = ((TPoint *) tR1->At(xx))->fTrans;
  638.         HLock((Handle) this);
  639.         SlopeIntercept(&line1);
  640.         dist1 = CalculateDistance(line1.first, line1.second);                        // get length of cell segments
  641.         interval1 = dist1 / gridLines;
  642.         
  643.         this->CalculateFinePt(&line1, gridLines, interval1, pt1);
  644.         HUnlock((Handle) this);
  645.         
  646.         for (yy = (short) this->fSize-1; yy > 0; yy--)
  647.             {
  648.             tR1 = tR2;                                                                                // assign tr1 to previous tr2
  649.             tR2 = (TRow *) this->At(yy);                                                    // get row above tr1
  650.             tPt                = (TPoint *)  tR1->At(xx+1);
  651.             line2.first        = ((TPoint *) tR2->At(xx+1))->fTrans;
  652.             line2.second    = ((TPoint *) tR2->At(xx))->fTrans;
  653.             HLock((Handle) this);
  654.             SlopeIntercept(&line2);
  655.             dist2 = CalculateDistance(line2.first, line2.second);
  656.             interval2 = dist2 / gridLines;                                                    // length of each sub-cell
  657.             
  658.             this->CalculateFinePt(&line2, gridLines, interval2, pt2);
  659.             HUnlock((Handle) this);
  660.             for (i = 0; i < gridLines-1; i++)
  661.                 {
  662.                 if (tPt->fObsUpLeft == NULL)
  663.                     {
  664.                     MoveTo(pt1[i].h+1,pt1[i].v+1);                                        // move to provided point
  665.                     LineTo (pt2[i].h+1, pt2[i].v+1);                                                // draw to this point
  666.                     }
  667.                 pt1[i].h = pt2[i].h;
  668.                 pt1[i].v = pt2[i].v;  
  669.                 }
  670.             }
  671.         }
  672.     }
  673.     
  674. // --------------------------------------------------------------------------------------------------
  675. //    TPointMatrix    :    CalculateFinePt .... 
  676. //        Calculates the location of the fine grid  points
  677. // -------------------------------------------------------------------------------------------------
  678. void  TPointMatrix::CalculateFinePt(lineSlope * line, short grid, extended dist, Point * p)
  679.     {
  680.     short        z, temp;
  681.     extended    t1, t2, t3, x, y;
  682.     extended      total;
  683.     
  684.     x = line->first.h;
  685.     y = line->first.v;
  686.     temp  = 0;
  687.     for (z = 0; z < grid-1; z++)                                                                // one for each subdivision - up to 15
  688.         {
  689.         if (line->vertical)                                                                            // is segment vertical?
  690.             {
  691.             if (line->first.v < line->second.v)
  692.                 y += dist;
  693.             else
  694.                 y -= dist;
  695.  
  696.              p[z].h = (short) x;
  697.             p[z].v = (short) y;
  698.             }
  699.         else if (line->horizontal)                                                                // is segment horizontal?
  700.             {
  701.             if (line->first.h < line->second.h)
  702.                 x += dist;
  703.             else
  704.                 x -= dist;
  705.  
  706.             p[z].h = (short) x;
  707.             p[z].v = (short) y;
  708.             }
  709.         else
  710.             {
  711.             t1 = dist / (sqrt((line->m * line->m) + 1));
  712.             if (temp == 0 || temp == 1)
  713.                 {
  714.                 x += t1;
  715.                 y = (line->m * x) + line->b;
  716.                 
  717.                 p[z].h = (short) x;
  718.                 p[z].v = (short) y;
  719.                 
  720.                 if (temp == 0)
  721.                     {
  722.                     t2 = CalculateDistance(line->first,p[z]);
  723.                     t3 = CalculateDistance(line->second,p[z]);
  724.                     total = CalculateDistance(line->first, line->second);
  725.                     
  726.                     if (t2 + t3 - 1 > total)                                                    // between the end points?
  727.                         {
  728.                         x = line->first.h;
  729.                         y = line->first.v;
  730.                         temp = 2;
  731.                         }
  732.                     else
  733.                         temp = 1;
  734.                     }
  735.                 }
  736.                                             
  737.             if (temp == 2)
  738.                 {
  739.                 x -= t1;
  740.                 y = (line->m * x) + line->b;
  741.  
  742.                 p[z].h = (short) x;
  743.                 p[z].v = (short) y;
  744.                 }
  745.             }
  746.         }
  747.     }        
  748.  
  749. // *********************************************************************************
  750. //    Boundry Methods
  751. // *********************************************************************************    
  752. // --------------------------------------------------------------------------------------------------
  753. //    TPointMatrix    :    RLBoundryDo
  754. //        Do the supplied method for left or right boundry
  755. // --------------------------------------------------------------------------------------------------
  756. void TPointMatrix::RLBoundryDo(pascal void (*DoToItem)(TObject *, void *), void *tinfo)
  757.     {
  758.     TBoundry     *    side;                                                                                // the boundry
  759.     TPoint        *    tPt;                                                                                // the point
  760.     PointInfo    *    info;                                                                                // information structure
  761.     short        index;                                                                                // counter
  762.     
  763.     info             = (PointInfo *) tinfo;
  764.     
  765.     if (fSize > 0)                                                                                        // any entries?
  766.         {
  767.         tPt                        = NULL;
  768.         info->belowRow    = NULL;
  769.         info->below            = NULL;                                                            // no points below on either boundry
  770.         info->aboveRow    = NULL;
  771.         info->above            = NULL;
  772.         info->oPt                = NULL;
  773.         info->lrc                = NULL;
  774.             
  775.         if (info->boundry == cRight)
  776.             side = fRight;
  777.         else
  778.             {
  779.             side = fLeft;
  780.             info->column            = 1;
  781.             }
  782.         info->left = (TPoint *) side->Last();
  783.             
  784.         for (index = (short) side->fSize; index > 0; index--)
  785.             {
  786.             info->right     = tPt;
  787.             tPt                = info->left;
  788.             if (index > 1)
  789.                 info->left = (TPoint *) side->At(index-1);
  790.             else
  791.                 info->left = NULL;
  792.             info->row = index;
  793.  
  794.             DoToItem((TObject *) tPt,info);
  795.             }
  796.         }
  797.     }
  798.     
  799. // --------------------------------------------------------------------------------------------------
  800. //    TRow    :    For Each point in the list Do the DoToItem Function
  801. // --------------------------------------------------------------------------------------------------
  802. void TPointMatrix::TBBoundryDo(pascal void (*DoToItem)(TObject *, void *), void *tInfo)
  803.     {
  804.     TRow        *    tRow;                                                                        // the row
  805.     PointInfo    *    info;                                                                            // information structure
  806.     
  807.     info = (PointInfo *) tInfo;                                                                // cast the structure
  808.     info->lrc                = NULL;
  809.     if (fSize > 0)                                                                                    // anything in the list?
  810.         {
  811.         if (info->boundry == cBottom)                                                    // bottom row
  812.             {
  813.             tRow                    = fBottom;                                                // last row
  814.             info->aboveRow    = NULL;
  815.             info->belowRow    = NULL;
  816.             info->row                = (short) fSize;
  817.             }
  818.         else                                                                                            // top roËœ
  819.             {
  820.             tRow                    = fTop;                                                        // last row
  821.             info->belowRow    = (TRow *) this->At(2);                            // get 2nd row
  822.             info->aboveRow    = NULL;
  823.             info->row                = 1;
  824.             }
  825.         
  826.         DoToItem((TObject *)tRow,info);                                                // perform the function
  827.         }
  828.     return;
  829.     }
  830.     
  831. // --------------------------------------------------------------------------------------------------
  832. //    TPointMatrix    :    FindBoundry
  833. // --------------------------------------------------------------------------------------------------
  834. short TPointMatrix::FindBoundry(TPoint * tPt)
  835.     {
  836.     short    rIndex;
  837.     
  838.     rIndex = (short) fTop->GetSameItemNo((TObject *) tPt);                    // search this row for mouse
  839.     if (rIndex != 0)    
  840.         {
  841.         fColumn    = rIndex;
  842.         fRow        = 1;
  843.         return cTop;                                                                                    // found point
  844.         }
  845.         
  846.     rIndex = (short) fBottom->GetSameItemNo((TObject *) tPt);                // search this row for mouse
  847.     if (rIndex != 0)
  848.         {
  849.         fColumn     = rIndex;
  850.         fRow        = (short) this->Last();
  851.         return cBottom;                                                                            // found point
  852.         }
  853.         
  854.     rIndex = (short) fLeft->GetSameItemNo((TObject *) tPt);                    // search this row for mouse
  855.     if (rIndex != 0)
  856.         {
  857.         fRow        =    rIndex;
  858.         fColumn    =    1;
  859.         return cLeft;                                                                                // found point
  860.         }
  861.  
  862.     rIndex = (short) fRight->GetSameItemNo((TObject *) tPt);                // search this row for mouse
  863.     if (rIndex != 0)
  864.         {
  865.         fRow        =    rIndex;
  866.         fColumn    =    (short) ((TRow *) this->At(fRow))->fSize;
  867.         return cRight;                                                                                // found point
  868.         }
  869.     
  870.     return NULL;
  871.     }
  872.     
  873. // --------------------------------------------------------------------------------------------------
  874. //    TPointMatrix    :    FindBoundryPoint
  875. // --------------------------------------------------------------------------------------------------
  876. TPoint * TPointMatrix::FindBoundryPoint(Point * tMouse)
  877.     {
  878.     short     index;
  879.     
  880.     index    =    fTop->SearchPoint(tMouse);                                                // search this row for mouse
  881.     if (index > 0)
  882.         {
  883.         fBoundry        = cTop;
  884.         fColumn        = index;
  885.         fRow            = 1;
  886.         return (TPoint *) fTop->At(index);                                                // found point
  887.         }
  888.                 
  889.     index    =    fBottom->SearchPoint(tMouse);                                        // search this row for mouse
  890.     if (index > 0)
  891.         {
  892.         fBoundry        = cBottom;
  893.         fColumn        = index;
  894.         fRow            = (short) this->fSize;
  895.         return  (TPoint *) fBottom->At(index);
  896.         }
  897.  
  898.     index    =    fLeft->SearchPoint(tMouse);                                                // search this row for mouse
  899.     if (index > 0)
  900.         {
  901.         fBoundry        = cLeft;
  902.         fColumn        = 1;
  903.         fRow            = index;
  904.         return  (TPoint *) fLeft->At(index);
  905.         }
  906.  
  907.     index    =    fRight->SearchPoint(tMouse);                                            // search this row for mouse
  908.     if (index > 0)
  909.         {
  910.         fBoundry        = cRight;
  911.         fColumn        = (short) ((TRow *) this->At(index))->fSize;
  912.         fRow            = index;
  913.         return  (TPoint *) fRight->At(index);
  914.         }
  915.     
  916.     return NULL;
  917.     }
  918.     
  919. // --------------------------------------------------------------------------------------------------
  920. //    TPointMatrix    :    FindBoundryPoint
  921. // --------------------------------------------------------------------------------------------------
  922. TPoint * TPointMatrix::FindPoint(Point * tMouse)
  923.     {
  924.     short x, index;
  925.     TRow    *    tRow;
  926.     TPoint    *    tPt;
  927.     
  928.     tPt = this->FindBoundryPoint(tMouse);                                                // boundries first
  929.     if (tPt != NULL)                                                                                    // if found point return it
  930.         return tPt;
  931.         
  932.     if (!fShown)                                                                                        // no grid
  933.         return NULL;                                                                                    // return not found
  934.         
  935.     fBoundry = cNotOnBoundry;                                                                // set current boundry
  936.     for (x = 2; x <= (short) (fSize - 1); x++)                                            // search grid rows
  937.         {
  938.         tRow = (TRow *) this->At(x);                                                        // get the row
  939.         index = tRow->SearchPoint(tMouse);                                            // search it
  940.         if (index > 0)                                                                                // if found return the point
  941.             {
  942.             fRow = x;
  943.             fColumn = index;
  944.             return (TPoint *) ((TRow *) this->At(x))->At(index);
  945.             }
  946.         }
  947.     return NULL;                                                                                        // not a point
  948.     }
  949.     
  950. // --------------------------------------------------------------------------------------------------
  951. //    TPointMatrix    :    FindSegment
  952. //        Determines which segment a particular boundry section is contained in.
  953. // --------------------------------------------------------------------------------------------------
  954. TSegPoint * TPointMatrix::FindSegment(TPoint * tPt, TRow * tside)
  955.     {
  956.     short         rIndex;
  957.     short         side, index;
  958.     short         e;
  959.                 
  960. //    this->SetCurrent(tPt);
  961.     e = (short) tside->fSize;
  962.     side = tside->GetSide();
  963.     if (side == cTop)
  964.         {
  965.         if (fColumn == 1)
  966.             index = 2;
  967.         else
  968.             index = fColumn;
  969.         }
  970.     else if (side == cBottom)
  971.         index = fColumn;
  972.     else
  973.         index = fRow;
  974.         
  975.     for (rIndex =  index; rIndex <= e; rIndex++)
  976.         {
  977.         tPt = (TPoint *) tside->At(rIndex);
  978.         if (tPt->IsSegment())
  979.             return (TSegPoint *) tPt;
  980.         }        
  981.     return NULL;
  982.     }
  983.         
  984. // --------------------------------------------------------------------------------------------------
  985. //    TPointMatrix    :    FindSection .... 
  986. //        determine which boundry section a segment or grid point is in
  987. // --------------------------------------------------------------------------------------------------
  988. TPoint * TPointMatrix::FindSection(Point * tMouse)
  989.     {    
  990.     if ((flocation = fTop->SearchSection(tMouse)) > 0)                                // found the section?
  991.         {
  992.         fRow            = 1;                                                                                // set the current row
  993.         fColumn        = flocation;                                                                    // set the current column
  994.         fBoundry        = cTop;
  995.         fOBoundry    = cBottom;
  996.         return ((TPoint *) fTop->At(flocation));
  997.         }
  998.     
  999.     if ((flocation = fBottom->SearchSection(tMouse)) > 0)                            // found section?
  1000.         {
  1001.         fRow             = (short) fSize;                                                            // set current row
  1002.         fColumn        = flocation;                                                                    // set current column
  1003.         fBoundry        = cBottom;
  1004.         fOBoundry    = cTop;
  1005.         return ((TPoint *) fBottom->At(flocation));
  1006.         }
  1007.  
  1008.     if ((flocation = fLeft->SearchSection(tMouse)) > 0)                                // test left boundry    
  1009.         {
  1010.         fRow            = flocation;                                                                    // set current row
  1011.         fColumn        = 1;                                                                                // set current column
  1012.         fBoundry        = cLeft;
  1013.         fOBoundry    = cRight;
  1014.         return ((TPoint *) fLeft->At(flocation));
  1015.         }
  1016.  
  1017.     if ((flocation = fRight->SearchSection(tMouse)) > 0)                                 // test right boundry
  1018.         {
  1019.         fRow            = flocation;                                                                    // set current row
  1020.         fColumn        = (short) ((TRow *) this->At(fRow))->fSize;                // set current column
  1021.         fBoundry        = cRight;
  1022.         fOBoundry    = cLeft;
  1023.         return ((TPoint *) fRight->At(flocation));
  1024.         }
  1025.     return NULL;
  1026.     }
  1027.  
  1028. // --------------------------------------------------------------------------------------------------
  1029. //    TPointMatrix    :    FindCell .... 
  1030. //        determine which cell the user has selected
  1031. // --------------------------------------------------------------------------------------------------
  1032. TPoint * TPointMatrix::FindCell(Point * tMouse, PointInfo * info)
  1033.     {    
  1034. // ....................................................................................................................................................................
  1035. //    This method impliments a searching algorithm to determine which grid cell was selected by the user
  1036. //    It performs a logrithmic binary search.
  1037. //    First examines the whole ... if the point is in the reqion
  1038. //    divides the whole into four pieces & locates the quadrant the point is in
  1039. //    divides that into four quadrants ... etc until only a single grid cell remains.
  1040. // ....................................................................................................................................................................
  1041.     char msg[80];
  1042.     
  1043.     if (!fShown)                                                                                                // have a grid?
  1044.         {
  1045.         SysBeep (3);
  1046.         TWarning * tWarning;
  1047.         TWindow    * aWindow;
  1048.         
  1049.         aWindow = NewTemplateWindow(kWarnMe, fDocument);
  1050.         tWarning = (TWarning *) aWindow->FindSubView('WARN');
  1051.         tWarning->IWarning(5,NULL);
  1052.         tWarning->ShowWarning();
  1053.         return NULL;
  1054.         }
  1055.     
  1056.     short    tRow, tCol;                                                                                    // total rows & columns
  1057.     short    sR, eR, sC, eC;                                                                                // start & end row / column
  1058.     short    saveS, saveE;                                                                                // save indexes
  1059.     Boolean notFound = true;                                                                            // found the point?
  1060.     RgnHandle        rgn;                                                                                        // draw region for "cell"
  1061.     Point            mPt;                                                                                        // mouse point
  1062.     info->oPt = info->above = info->left = info->right = info->below = NULL;
  1063.     
  1064.     tRow    = eR = (short) this->fSize;                                                            // init number rows
  1065.     tCol        = eC = (short) fTop->fSize;                                                            // init number columns
  1066.     sR        = sC = 1;                                                                                        // begin at 1,1
  1067.     saveS    = saveE = 0;                                                                                    // init save variables
  1068.     mPt.v    = tMouse->v;
  1069.     mPt.h    = tMouse->h;
  1070.     
  1071.     rgn = NewRgn();                                                                                        // create the region handle
  1072.     while (notFound)                                                                                        // loop till find the point
  1073.         {
  1074.         this->DefineSearchRegion(info,rgn,sR,eR,sC,eC);                                    // draw the region
  1075.         if (PtInRgn (mPt,rgn))                                                                            // in this region?
  1076.             {                                                                                                        // yes it is!
  1077.             if (sR + 1 == eR && sC + 1 == eC)                                                    // have only 1 cell
  1078.                 {
  1079.                 DisposeRgn(rgn);                                                                            // free the region
  1080.                 fRow        = sR;                                                                            // set current row / column
  1081.                 fColumn    = sC;
  1082.                 sprintf(msg,"Selected Cell R %d C %d",sR,sC);
  1083.                 ((TCFDFrontDocument *) fDocument)->fInfoView->InfoString(msg);
  1084.                 return (TPoint *) ((TRow *) this->At(sR))->At(sC);
  1085.                 }
  1086.             tRow    = eR;                                                                                    // reset bottom
  1087.             tCol        = eC;
  1088.             eR        = sR + ((eR - sR) / 2);                                                            // reset search quadrant
  1089.             eC        = sC + ((eC - sC) / 2);
  1090.         if (sR < 1 || sR > tRow || eR < 1 || eR > tRow)
  1091.             msg[0] = 0;
  1092.         if (sC < 1 || sC > tCol || eC < 1|| eC > tCol)
  1093.             msg[0] = 0;
  1094.             
  1095.             }
  1096.         else                                                                                                        // not in this quadrant
  1097.             {
  1098.             if (eC < tCol)                                                                                        // left side quadrants
  1099.                 {
  1100.                 saveS    = sC;                                                                                // store current start column
  1101.                 saveE    = eC;                                                                                // store current end column
  1102.                 sC        = eC;                                                                                // reset to right quadrant
  1103.                 eC        = tCol;                                                                                // reset to right quadrant
  1104.         if (sR < 1 || sR > tRow || eR < 1 || eR > tRow)
  1105.             msg[0] = 0;
  1106.         if (sC < 1 || sC > tCol || eC < 1|| eC > tCol)
  1107.             msg[0] = 0;
  1108.             
  1109.                 }
  1110.             else if (eR < tRow)                                                                            // upper quadrants
  1111.                 {
  1112.                 sC    = saveS;                                                                                // reset start column to left side
  1113.                 eC    = saveE;                                                                                // reset end column to left side
  1114.                 sR    = eR;                                                                                    // reset start row to bottom quadrants
  1115.                 eR    = tRow;                                                                                // reset end row to bottom quadrants
  1116.         if (sR < 1 || sR > tRow || eR < 1 || eR > tRow)
  1117.             msg[0] = 0;
  1118.         if (sC < 1 || sC > tCol || eC < 1|| eC > tCol)
  1119.             msg[0] = 0;
  1120.             
  1121.                 }
  1122.             else
  1123.                 {
  1124.                 DisposeRgn(rgn);                                                                            // free the region
  1125.                 SysBeep (3);
  1126.                 TWarning * tWarning;
  1127.                 TWindow    * aWindow;
  1128.         
  1129.                 aWindow = NewTemplateWindow(kWarnMe, fDocument);
  1130.                 tWarning = (TWarning *) aWindow->FindSubView('WARN');
  1131.                 tWarning->IWarning(4,NULL);
  1132.                 tWarning->ShowWarning();
  1133.                 return NULL;
  1134.                 }
  1135.             }
  1136.         }
  1137.     return NULL;
  1138.     }
  1139.  
  1140. // --------------------------------------------------------------------------------------------------
  1141. //    TPointMatrix    :    DefineSearchRegion .... 
  1142. //        Draws the region to be searched in the FindCell method
  1143. // --------------------------------------------------------------------------------------------------
  1144. void  TPointMatrix::DefineSearchRegion(PointInfo * info, RgnHandle rgn, short sR,short eR,short sC,short eC)
  1145.     {
  1146.     Point        ul, tPt;
  1147.     short        cR, cC;                                                                                        // current row / column
  1148.     
  1149.     cR = sR;                                                                                                    // row to start on
  1150.     SetEmptyRgn(rgn);                                                                                    // clear the region
  1151.     OpenRgn();                                                                                                // open drawing area
  1152.     info->oPt        = (TPoint *) ((TRow *) this->At(sR))->At(sC);                        // get starting point
  1153.     info->above    = (TPoint *) ((TRow *) this->At(sR))->At(eC);
  1154.     info->left        = (TPoint *) ((TRow *) this->At(eR))->At(sC);
  1155.     info->below    = (TPoint *) ((TRow *) this->At(eR))->At(eC);
  1156.     ul = info->oPt->fStart;                                                                                // get coordinates
  1157.     MoveTo(ul.h, ul.v);                                                                                    // position pen
  1158.     
  1159. //    draw across top of the region (left to right)
  1160.     for (cC = sC; cC <= eC; cC++)                                                                    // do all columns
  1161.         {
  1162.         tPt = ((TPoint *) ((TRow *) this->At(cR))->At(cC))->fStart;
  1163.         LineTo (tPt.h, tPt.v);
  1164.         }
  1165.     cC = eC;
  1166.  
  1167. //    draw down right side of the region (top to bottom)
  1168.     for (cR = sR; cR <= eR; cR++)                                                                    // do all rows
  1169.         {
  1170.         tPt = ((TPoint *) ((TRow *) this->At(cR))->At(cC))->fStart;
  1171.         LineTo (tPt.h, tPt.v);
  1172.         }
  1173.     cR = eR;
  1174.  
  1175. //    draw across bottom of the region (right to left)
  1176.     for (cC = eC; cC >= sC; cC--)                                                                    // do all columns
  1177.         {
  1178.         tPt = ((TPoint *) ((TRow *) this->At(cR))->At(cC))->fStart;
  1179.         LineTo (tPt.h, tPt.v);
  1180.         }
  1181.     cC = sC;
  1182.  
  1183. //    draw up left side of the region (bottom to top)
  1184.     for (cR = eR; cR >= sR; cR--)                                                                    // do all rows
  1185.         {
  1186.         tPt = ((TPoint *) ((TRow *) this->At(cR))->At(cC))->fStart;
  1187.         LineTo (tPt.h, tPt.v);
  1188.         }
  1189.     
  1190.     CloseRgn (rgn);
  1191.     return;
  1192.     }
  1193.     
  1194. // --------------------------------------------------------------------------------------------------
  1195. //    TPointMatrix    :    FindLine .... 
  1196. //        determine which line the user has selected
  1197. // --------------------------------------------------------------------------------------------------
  1198. short TPointMatrix::FindLine (Point * tMouse, PointInfo * info)
  1199.     {    
  1200. // ....................................................................................................................................................................
  1201. //    This method impliments a searching algorithm to determine which grid line was selected by the user
  1202. // ....................................................................................................................................................................
  1203. //    search the horizontal lines first
  1204.  
  1205.     short    i, tmp;
  1206.     TRow    * tRow;
  1207.     char        msg[80];
  1208.     
  1209.     info->above = info->below = info->left = info->right = NULL;
  1210.     
  1211.     for (i = 1; i <= (short) this->fSize; i++)
  1212.         {
  1213.         tRow = (TRow *) this->At(i);
  1214.         if ((tmp = tRow->SearchSection(tMouse)) > 0)
  1215.             {
  1216.             fRow        = i;                                                                                    // reset currents
  1217.             fColumn    = tmp-1;
  1218.             info->left        = (TPoint *) tRow->At(fColumn);
  1219.             info->right    = (TPoint *) tRow->At(tmp);
  1220.             sprintf(msg,"Selected Horizontal Grid Line: R [%d] C1 [%d] C2 [%d]",i,tmp-1,tmp);
  1221.             ((TCFDFrontDocument *) fDocument)->fInfoView->InfoString(msg);
  1222.             return 2;
  1223.             }
  1224.         }
  1225.  
  1226.     for (i = 1; i <= (short) fTop->fSize; i++)
  1227.         {
  1228.         if ((tmp = this->SearchColumnSection (i,tMouse,info)) > 0)
  1229.             {
  1230.             fRow        = tmp - 1;
  1231.             fColumn    = i;
  1232.             sprintf(msg,"Selected Vertical Grid Line: R1 [%d] R2 [%d] C [%d]",tmp-1,tmp, i);
  1233.             ((TCFDFrontDocument *) fDocument)->fInfoView->InfoString(msg);
  1234.             return 1;
  1235.             }
  1236.         }
  1237.     return 0;
  1238.     }
  1239.  
  1240. // --------------------------------------------------------------------------------------------------
  1241. //    TPointMatrix    :    SelectSegment .... 
  1242. //        changes the wall type for each section in this segment
  1243. // --------------------------------------------------------------------------------------------------
  1244. void  TPointMatrix::SelectSegment(TPoint * tPt, TRow * tSide, Boolean on)
  1245.     {
  1246.     short side;                                                                                                // the boundry
  1247.     short index;                                                                                                // counter
  1248.     TPoint * t;
  1249.     
  1250.     side = tSide->GetSide();                                                                            // gets the boundry
  1251.     this->SetCurrent(tPt);                                                                                // sets tpt as current
  1252.     
  1253.     if (side == cTop || side == cBottom)
  1254.         index = fColumn;
  1255.     else
  1256.         index = fRow;
  1257.         
  1258.     t = (TPoint *) tSide->At(index);                                                                // get the point
  1259.     t->SetSelection(on);
  1260.     index--;
  1261.     
  1262.     while (index > 0)                                                                                        // do until begin of list
  1263.         {
  1264.         t = (TPoint *) tSide->At(index);                                                            // get the point
  1265.         if (t->IsSegment())                                                                                // is the point a segment
  1266.             return;                                                                                                // yes : exit loop
  1267.         t->SetSelection(on);                                                                                // turn on
  1268.         index--;                                                                                                // next point
  1269.         }
  1270.     return;
  1271.     }
  1272.     
  1273. // --------------------------------------------------------------------------------------------------
  1274. //    TPointMatrix    :    SetSegment .... 
  1275. //        changes the wall type for each section in this segment
  1276. // --------------------------------------------------------------------------------------------------
  1277. void  TPointMatrix::SetSegment(TPoint * tPt, TRow * tSide, short type)
  1278.     {
  1279.     short side;                                                                                                // the boundry
  1280.     short index;                                                                                                // counter
  1281.     TPoint * t;
  1282.     
  1283.     side = tSide->GetSide();                                                                            // gets the boundry
  1284.     this->SetCurrent(tPt);                                                                                // sets tpt as current
  1285.     
  1286.     if (side == cTop || side == cBottom)
  1287.         index = fColumn;
  1288.     else
  1289.         index = fRow;
  1290.         
  1291.     if (side == cRight && index == fSize)
  1292.         t = (TPoint *) tSide->Last();
  1293.     else
  1294.         t = (TPoint *) tSide->At(index);                                                            // get the point
  1295.     t->SetSectionType(type);                                                                            // turn on
  1296.     index--;                                                                                                    // next point
  1297.  
  1298.     while (index > 0)                                                                                        // do until begin of list
  1299.         {
  1300.         t = (TPoint *) tSide->At(index);                                                            // get the point
  1301.         if (t->IsSegment())                                                                                // is the point a segment
  1302.             return;                                                                                                // yes : exit loop
  1303.         t->SetSectionType(type);                                                                        // turn on
  1304.         index--;                                                                                                // next point
  1305.         }
  1306.     return;
  1307.     }
  1308.     
  1309. // *********************************************************************************
  1310. //    Add Segment Methods
  1311. // *********************************************************************************
  1312. // --------------------------------------------------------------------------------------------------
  1313. //    TPointMatrix    :    AddAt .... 
  1314. //        adds the segment... if it requires a new row this method creates it
  1315. // --------------------------------------------------------------------------------------------------
  1316. Boolean TPointMatrix::AddAt(TPoint * pt1, TPoint * pt2, short row, short col)
  1317.     {
  1318.     TRow     * tRow;                                                                                    // pointer to new row
  1319.     TRow     * side;
  1320.  
  1321.     side = (TRow *) this->GetCurrentBoundry();
  1322.     
  1323.     if (fBoundry == cLeft || fBoundry == cRight)                                            // left or right side create a new row
  1324.         {
  1325.         tRow = new TRow;                                                                            // allocate space for new row
  1326.         if (tRow == NULL)                                                                                // no more space
  1327.             return false;                                                                                    // return error
  1328.         if (fBoundry == cLeft)                                                                        // left side
  1329.             {
  1330.             fLeft->InsertBefore(row,(TObject *) pt1);
  1331.             fRight->InsertBefore(row,(TObject *) pt2);
  1332.             tRow->IRow(pt1,pt2);                                                                    // initialize row
  1333.             }
  1334.         else
  1335.             {
  1336.             fLeft->InsertBefore(row,(TObject *) pt2);
  1337.             fRight->InsertBefore(row,(TObject *) pt1);
  1338.             tRow->IRow(pt2,pt1);                                                                    // initialize row
  1339.             }
  1340.         this->InsertBefore(row, (TObject *) tRow);                                        // add row to the matrix
  1341.         
  1342.         this->CreateGridRow(row);
  1343.             
  1344.         return true;
  1345.         }
  1346.         
  1347.     if (fBoundry == cTop)
  1348.         {
  1349.         fTop->InsertBefore(col, (TObject *) pt1);
  1350.         fBottom->InsertBefore(col, (TObject *) pt2);
  1351.         tRow = (TRow *) this->First();
  1352.         tRow->InsertBefore(col, (TObject *) pt1);                                        // add new column to row
  1353.         tRow = (TRow *) this->Last();                                                            // get bottom boundry
  1354.         }
  1355.     else
  1356.         {
  1357.         fTop->InsertBefore(col, (TObject *) pt2);
  1358.         fBottom->InsertBefore(col, (TObject *) pt1);
  1359.         tRow = (TRow *) this->Last();
  1360.         tRow->InsertBefore(col, (TObject *) pt1);                                        // add new column to row
  1361.         tRow = (TRow *) this->First();                                                            // get top boundry
  1362.         }
  1363.     tRow->InsertBefore(col, (TObject *) pt2);                                            // add opposite point
  1364.     
  1365.     this->CreateGridColumn(col);    
  1366.     return true;        
  1367.     }
  1368.  
  1369. // --------------------------------------------------------------------------------------------------
  1370. //    TPointMatrix    :    GetOpposite .... 
  1371. //        determine the location of the new point on the opposite boundry
  1372. // --------------------------------------------------------------------------------------------------
  1373. TGPoint * TPointMatrix::GetOpposite(Point * tMouse, PointInfo * tInfo, PointInfo * oInfo)
  1374.     {
  1375.     lineSlope     tSlope;
  1376.     TGPoint    * tPt;
  1377.     TPoint         * pt1, * ot1, * ot2;
  1378.     Point        tPt1, tPt2;
  1379.     Point        oPt1, oPt2;
  1380.     Point        nPt;
  1381.     extended     dist1, dist2, odist;
  1382.     extended     ratio, dist2Pt;
  1383.     
  1384. //    get the points on the opposite boundry    
  1385.     switch (fOBoundry)
  1386.         {
  1387.         case cTop:
  1388.             tPt2 = ((TPoint *) fBottom->At(fColumn))->fStart;
  1389.             pt1 = (TPoint *) fBottom->At(fColumn-1);
  1390.             ot1 = (TPoint *) fTop->At(fColumn-1);
  1391.             ot2 = (TPoint *) fTop->At(fColumn);
  1392.             break;
  1393.         case cBottom:            
  1394.             tPt2 = ((TPoint *) fTop->At(fColumn))->fStart;
  1395.             pt1 = (TPoint *) fTop->At(fColumn-1);
  1396.             ot1 = (TPoint *) fBottom->At(fColumn-1);
  1397.             ot2 = (TPoint *) fBottom->At(fColumn);
  1398.             break;
  1399.         case cLeft:
  1400.             tPt2 = ((TPoint *) fRight->At(fRow))->fStart;
  1401.             pt1 = (TPoint *) fRight->At(fRow-1);
  1402.             ot1 = (TPoint *) fLeft->At(fRow-1);
  1403.             ot2 = (TPoint *) fLeft->At(fRow);
  1404.             break;
  1405.         case cRight:
  1406.             tPt2 = ((TPoint *) fLeft->At(fRow))->fStart;
  1407.             pt1 = (TPoint *) fLeft->At(fRow-1);
  1408.             ot1 = (TPoint *) fRight->At(fRow-1);
  1409.             ot2 = (TPoint *) fRight->At(fRow);
  1410.             break;
  1411.         }
  1412.     
  1413.     tInfo->left = pt1;
  1414.     oInfo->left = ot1;
  1415.     oInfo->right = ot2;
  1416.     
  1417.     tPt1 = pt1->fStart;
  1418.     oPt1 = ot1->fStart;
  1419.     oPt2 = ot2->fStart;
  1420.     oInfo->boundry = fOBoundry;
  1421.  
  1422.     dist1 = CalculateDistance(* tMouse, tPt1);                                    // distance between mouse & left
  1423.     dist2 = CalculateDistance(tPt1, tPt2);                                            // distance between endpoints
  1424.     if (dist2 == 0)
  1425.         return NULL;
  1426.     
  1427.     ratio = dist1/dist2;                                                                        // get the ratio of the distances
  1428.  
  1429.     odist = CalculateDistance(oPt1, oPt2);                                            // distance between opp endpoints
  1430.     dist2Pt = ratio * odist;                                                                    // distance to the point
  1431.  
  1432.     tSlope.first        = oPt1;                                                                    // set points to get slope
  1433.     tSlope.second    = oPt2;
  1434.     HLock((Handle) this);
  1435.     SlopeIntercept(&tSlope);                                                                // calculate slope
  1436.             
  1437.     nPt        = this->CalculateLocation(&tSlope,odist,dist2Pt);                // point location
  1438.     HUnlock((Handle) this);
  1439.  
  1440.     tPt = new TGPoint;
  1441.     if (tPt == NULL)
  1442.         return NULL;
  1443.     tPt->IPoint(nPt.v, nPt.h,(ot2->GetSectionType()),((TGeomView *) fGeomView)->fMagnify);        // create the point
  1444.     return tPt;
  1445.     }
  1446.     
  1447. // *********************************************************************************
  1448. //    Grid / Boundry Methods
  1449. //        these methods work on the entire mesh ... this includes the boundry
  1450. // *********************************************************************************
  1451. // --------------------------------------------------------------------------------------------------
  1452. //    TPointMatrix    :    SearchColumn .... 
  1453. //        try to match the location of the mouse point to an object point in this column only works with grid on
  1454. // --------------------------------------------------------------------------------------------------
  1455. TPoint * TPointMatrix::SearchColumnPoint(short index, Point * tMouse)
  1456.     {
  1457.     short rIndex;
  1458.     TPoint * tPt;
  1459.     
  1460.     for (rIndex = 1; rIndex <= fSize; rIndex++)
  1461.         {
  1462.         tPt = (TPoint *)((TRow *) this->At(rIndex))->At(index);
  1463.         if (tPt->OnPoint(tMouse))
  1464.             {
  1465.             fRow = rIndex;
  1466.             fColumn = index;
  1467.             return tPt;
  1468.             }
  1469.         }
  1470.     return NULL;
  1471.     }
  1472.     
  1473. // --------------------------------------------------------------------------------------------------
  1474. //    TPointMatrix    :    SearchColumn .... 
  1475. //        try to match the location of the mouse point to a line between point objects
  1476. // --------------------------------------------------------------------------------------------------
  1477. short TPointMatrix::SearchColumnSection(short index, Point * tMouse, PointInfo * info)
  1478.     {
  1479.     short rIndex;
  1480.     TPoint * tPt1, * tPt2;
  1481.     Point    pt1, pt2;
  1482.     
  1483.     tPt1    = (TPoint *) ((TRow *) this->First())->At(index);                        // first point in column
  1484.     pt1    = tPt1->fStart;                                                                            // actual location
  1485.     for (rIndex = 2; rIndex <= fSize; rIndex++)
  1486.         {
  1487.         tPt2    = (TPoint *)((TRow *) this->At(rIndex))->At(index);
  1488.         pt2    = tPt2->fStart;
  1489.         info->above = tPt1;
  1490.         info->below = tPt2;
  1491.         if (((TRow *) this->At(rIndex))->PointOnLine(pt1,pt2,tMouse))
  1492.             {
  1493.             fRow = rIndex;
  1494.             fColumn = index;
  1495.             return rIndex;
  1496.             }
  1497.  
  1498.         tPt1    = tPt2;
  1499.         pt1    = pt2;
  1500.         }
  1501.     return 0;
  1502.     }
  1503.     
  1504. // **********************************************************************
  1505. // --------------------------------------------------------------------------------------------------
  1506. //    TPointMatrix    :    EachRowDo
  1507. //        Do the supplied method for each row
  1508. // --------------------------------------------------------------------------------------------------
  1509. pascal void TPointMatrix::Each(pascal void (*DoToItem)(TObject *, void *), void*DoToItem_StaticLink)
  1510.     {
  1511.     TRow         * tRow;
  1512.     PointInfo    * info;
  1513.     short         index;
  1514.      
  1515.     info = (PointInfo *) DoToItem_StaticLink;                                            // cast info to type PointInfo
  1516.  
  1517.     if (fSize > 0)                                                                                        // anything in the list?
  1518.         {
  1519.         tRow                    = NULL;                                                            // initialize the row
  1520.         info->aboveRow    = (TRow *) this->At(fSize);                                // get bottom row
  1521.         info->boundry        = cBottom;                                                        // initialize the boundry type
  1522.         info->lrc                = (TPoint *) fRight->Last();
  1523.         for (index = (short) fSize; index > 0; index--)                                // do all rows
  1524.             {
  1525.             info->belowRow    = tRow;                                                        // assign the row below this one
  1526.             tRow                    = info->aboveRow;                                        // assign current row
  1527.             if (index > 1)                                                                            // on top row?
  1528.                 info->aboveRow = (TRow *) this->At(index-1);                    // get new above row
  1529.             else
  1530.                 {
  1531.                 info->aboveRow    = NULL;                                                    // on top
  1532.                 info->boundry        = cTop;                                                        // assign new boundry
  1533.                 }
  1534.             info->row                    = index;                                                    // assign current row
  1535.             DoToItem(tRow, info);                                                                // perform the function
  1536.             info->boundry = cNotOnBoundry;                                                // reassign the boundry
  1537.             }
  1538.         }
  1539.     return;
  1540.     }
  1541.     
  1542. // --------------------------------------------------------------------------------------------------
  1543. //    TPointMatrix    :    OneRowDo
  1544. //        Do the supplied method for each column
  1545. // --------------------------------------------------------------------------------------------------
  1546. void TPointMatrix::OneRowDo(pascal void (*DoToItem)(TObject *, void *), void *tinfo)
  1547.     {
  1548.     TRow * tRow;
  1549.     PointInfo * info;
  1550.     
  1551.     info             = (PointInfo *) tinfo;
  1552.     info->lrc    = NULL;
  1553.     
  1554.     if (info->row <= 0 || info->row > (short) fSize)
  1555.         return;
  1556.     
  1557.     info->noGrid        =    fShown;
  1558.     info->boundry    = cNotOnBoundry;
  1559.     if (info->row > 1)
  1560.         info->aboveRow = (TRow *) this->At(info->row-1);
  1561.     else
  1562.         {
  1563.         info->aboveRow    = NULL;
  1564.         info->boundry        = cTop;
  1565.         }
  1566.     
  1567.     if (info->row < (short) fSize)
  1568.         info->belowRow = (TRow *) this->At(info->row+1);
  1569.     else
  1570.         {
  1571.         info->belowRow    = NULL;
  1572.         info->boundry        = cBottom;
  1573.         info->lrc    = (TPoint *) fRight->Last();
  1574.         }
  1575.     tRow = (TRow *) this->At(info->row);
  1576.     DoToItem((TObject *) tRow, info);    
  1577.     }
  1578.     
  1579. // --------------------------------------------------------------------------------------------------
  1580. //    TPointMatrix    :    EachColumnDo
  1581. //        Do the supplied method for each column
  1582. // --------------------------------------------------------------------------------------------------
  1583. void TPointMatrix::OneColumnDo(pascal void (*DoToItem)(TObject *, void *), void *tinfo)
  1584.     {
  1585.     TPoint        *    tPt;                                                                                // the point
  1586.     TRow        *     tRow;                                                                            // the row
  1587.     PointInfo    *    info;                                                                                // information structure
  1588.     short        index;                                                                                // counter
  1589.     
  1590.     info             = (PointInfo *) tinfo;
  1591.     
  1592.     if (fSize > 0)                                                                                        // any entries?
  1593.         {
  1594.         tRow            = NULL;                                                                    // initialize the row
  1595.         tPt                = NULL;                                                                    // initialize the point
  1596.         info->right    = NULL;                                                                    // initialize the right point
  1597.         info->aboveRow    = (TRow *) this->Last();                                    // get last row
  1598.         info->boundry        = cBottom;
  1599.         info->lrc                = (TPoint *) fRight->Last();
  1600.         info->above            = (TPoint *) info->aboveRow->At(info->column);    // get point above this
  1601.             
  1602.         if (info->column > 1)                                                                        // on left boundry?
  1603.             info->oPt = (TPoint *) info->aboveRow->At(info->column-1);    // get obstacle point
  1604.         else
  1605.             info->oPt = NULL;                                                                        // no point there
  1606.             
  1607.         for (index = (short) fSize; index > 0; index--)                                // do all rows in this column
  1608.             {
  1609.             info->belowRow    =    tRow;                                                        // assign row below
  1610.             info->below            =    tPt;                                                            // assign point below
  1611.             tRow                    =    info->aboveRow;                                        // assign current row
  1612.             tPt                        =    info->above;                                                // assign current point
  1613.             info->left                =    info->oPt;                                                    // assign point to left
  1614.             if (index > 1)                                                                            // on top boundry?
  1615.                 {
  1616.                 info->aboveRow     = (TRow *) this->At(index-1);                    // get new row above
  1617.                 info->above             = (TPoint *) (info->aboveRow)->At(info->column); // get new above point
  1618.                 if (info->column > 1)                                                                // on left boundry?
  1619.                     info->oPt = (TPoint *) (info->aboveRow)->At(info->column-1); // get new obstacle point
  1620.                 }
  1621.             else
  1622.                 {
  1623.                 info->boundry        = cTop;
  1624.                 info->aboveRow    = NULL;
  1625.                 info->above            = NULL;
  1626.                 info->oPt                = NULL;                                                    // no row ; no points
  1627.                 }
  1628.             if (info->column < (tRow->fSize))                                                // on right boundry?
  1629.                 info->right = (TPoint *) tRow->At(info->column+1);                // get point to right
  1630.                 
  1631.             info->row = index;                                                                    // assign the column
  1632.             
  1633.             DoToItem((TObject *) tPt,info);
  1634.             info->lrc = NULL;
  1635.             info->boundry = cNotOnBoundry;
  1636.             }
  1637.         }
  1638.     }
  1639.  
  1640. // **********************************************************************
  1641. // --------------------------------------------------------------------------------------------------
  1642. //    TPointMatrix    :    CalculateLocation
  1643. //        creates a row of grid points
  1644. // --------------------------------------------------------------------------------------------------
  1645. Point TPointMatrix::CalculateLocation(lineSlope * line, extended d3, extended dist)
  1646.     {
  1647.     extended        x, y;
  1648.     extended        d1, d2, d4;
  1649.     Point            nPt;
  1650.  
  1651.     if (line->vertical)                                                                            // vertical line
  1652.         {
  1653.         x = (extended) line->first.h;                                                        // set x coordinate
  1654.         if (line->first.v < line->second.v)
  1655.             y = (extended) line->first.v + dist;                                        // set y coordinate
  1656.         else
  1657.             y = (extended) line->first.v - dist;                                        // set y coordinate
  1658.         }
  1659.     else if (line->horizontal)                                                                // horizontal line
  1660.         {
  1661.         y = (extended) line->first.v;                                                        // set y coordinate
  1662.         if (line->first.h < line->second.h)                                                    
  1663.             x = (extended) line->first.h + dist;                                        // set x coordinate
  1664.         else
  1665.             x = (extended) line->first.h - dist;                                        // set x coordinate
  1666.         }
  1667.     else
  1668.         {
  1669.         d4 = dist / (sqrt((line->m * line->m) + 1));                                // dist to point 
  1670.         x = line->first.h + d4;                                                                // set x coordinate
  1671.         y = (line->m * x) + line->b;                                                        // set y coordinate
  1672.         nPt.h = (short) x;
  1673.         nPt.v = (short) y;
  1674.             
  1675.         d2 = CalculateDistance(line->first,nPt);
  1676.         d1 = CalculateDistance(line->second,nPt);
  1677.         if ((d1+d2 - .5) > d3)                                                                // wrong direction
  1678.             {
  1679.             x = line->first.h - d4;                                                            // set x coordinate
  1680.             y = (line->m * x) + line->b;                                                    // set y coordinate
  1681.             }
  1682.         }
  1683.     nPt.h = (short) x;
  1684.     nPt.v = (short) y;
  1685.     return nPt;
  1686.     }
  1687.     
  1688. // --------------------------------------------------------------------------------------------------
  1689. //    TPointMatrix    :    CreateGridRow
  1690. //        creates a row of grid points
  1691. // --------------------------------------------------------------------------------------------------
  1692. TRow * TPointMatrix::CreateGridRow(short row)
  1693.     {
  1694.     short i;
  1695.     lineSlope        line;                                                                                // line segment information
  1696.     TGridPoint    *    nPoint;                                                                        // internal grid point
  1697.     TRow            *    tRow;
  1698.     extended        ratioLeft, ratioRight, dist;
  1699.     extended        ld1, rd1, tl1, tr1, td, d2, d3;
  1700.     Point            l1, l2, l3, r1, r2, r3, nPt;
  1701.     
  1702. //    get points locations on the left & right boundry
  1703.     tRow = (TRow *) this->At(row);
  1704.     l1 = ((TPoint *) ((TRow *) this->At(row-1))->First())->fStart;
  1705.     l2 = ((TPoint *) ((TRow *) this->At(row+1))->First())->fStart;
  1706.     l3 = ((TPoint *) tRow->First())->fStart;
  1707.     r1 = ((TPoint *) ((TRow *) this->At(row-1))->Last())->fStart;
  1708.     r2 = ((TPoint *) ((TRow *) this->At(row+1))->Last())->fStart;
  1709.     r3 = ((TPoint *) tRow->Last())->fStart;
  1710.     
  1711.     ld1    = CalculateDistance(l1,l3);                                                        // distance from pt above to this row
  1712.     tl1    = CalculateDistance(l1,l2);                                                        // distance from pt  above to pt below
  1713.     rd1    = CalculateDistance(r1,r3);                                                        // distance from pt above to this row
  1714.     tr1    = CalculateDistance(r1,r2);                                                        // distance from pt  above to pt below
  1715.     td        = CalculateDistance(l1,r1);                                                        // distance for wieght factor
  1716.     
  1717.     ratioLeft    = ld1 / tl1;                                                                        // ratio of dist to point left boundry
  1718.     ratioRight    = rd1 / tr1;                                                                        // ratio of dist to point right boundry
  1719.     for (i = 2; i < (short) fTop->fSize; i++)
  1720.         {
  1721.         line.first        = ((TPoint *) ((TRow *) this->At(row-1))->At(i))->fStart;
  1722.         line.second    = ((TPoint *) ((TRow *) this->At(row+1))->At(i))->fStart;
  1723.         HLock((Handle) this);
  1724.         SlopeIntercept(&line);                                                                    // get slope of line to dissect
  1725.  
  1726.         d3    =     CalculateDistance(line.first,line.second);                            // calculate distance between points
  1727.         d2    =    CalculateDistance(l1,line.first);                                        // distance for wiıght factor
  1728.         dist    =    (((d2/td) * ratioLeft) + ((1 - d2/td) * ratioRight)) * d3;    // distance down line 
  1729.         
  1730.         nPt        = CalculateLocation(&line,d3,dist);                                    // point location
  1731.         HUnlock((Handle) this);
  1732.             
  1733.         nPoint = tRow->AddPointAt(i,nPt,((TGeomView *) fGeomView)->fMagnify);    // add point to row
  1734.         }        
  1735.     return tRow;
  1736.     }
  1737.  
  1738. // --------------------------------------------------------------------------------------------------
  1739. //    TPointMatrix    :    CreateGridColumn
  1740. //        creates a column of grid points
  1741. // --------------------------------------------------------------------------------------------------
  1742. TRow * TPointMatrix::CreateGridColumn(short column)
  1743.     {
  1744.     short i;
  1745.     lineSlope    line;
  1746.     TGridPoint    *    nPoint;                                                                        // internal grid point
  1747.     TRow            *    tRow;
  1748.     extended        ratioTop, ratioBottom, dist;
  1749.     extended        td1, bd1, tt1, tb1, td, d2, d3;
  1750.     Point            t1, t2, t3, b1, b2, b3, nPt;
  1751.  
  1752. //    get point locations on the top & bottom boundry
  1753.     t1        =    ((TPoint *) ((TRow *) this->First())->At(column-1))->fStart;
  1754.     t2        =    ((TPoint *) ((TRow *) this->First())->At(column+1))->fStart;
  1755.     t3        =    ((TPoint *) ((TRow *) this->First())->At(column))->fStart;
  1756.     b1    =    ((TPoint *) ((TRow *) this->Last())->At(column-1))->fStart;
  1757.     b2    =    ((TPoint *) ((TRow *) this->Last())->At(column+1))->fStart;
  1758.     b3    =    ((TPoint *) ((TRow *) this->Last())->At(column))->fStart;
  1759.     
  1760.     td1    =    CalculateDistance(t1,t3);                                                        // distance of top segment
  1761.     tt1    =    CalculateDistance(t1,t2);                                                        // total distance of top segment
  1762.     bd1    =    CalculateDistance(b1,b3);                                                        // distance of bottom segment
  1763.     tb1    =    CalculateDistance(b1,b2);                                                        // total distance of bottom segment
  1764.     td        =    CalculateDistance(t1,b1);                                                        // weight factor
  1765.     
  1766.     ratioTop        =    td1 / tt1;                                                                    // ratio of dist to point : top boundry
  1767.     ratioBottom    =    bd1 / tb1;                                                                // ratio of dist to point : bottom boundry
  1768.  
  1769.     for (i = 2; i < (short) fSize; i++)
  1770.         {
  1771.         tRow = (TRow *) this->At(i);                                                        // this row
  1772.         line.first         =     ((TPoint *) tRow->At(column-1))->fStart;            // end points for line to bisect        
  1773.         line.second    =    ((TPoint *) tRow->At(column))->fStart;
  1774.         HLock((Handle) this);
  1775.         SlopeIntercept(&line);                                                                    // get slope of line
  1776.         
  1777.         d3     = CalculateDistance(line.first,line.second);                            // length of bisect line
  1778.         d2     = CalculateDistance(t1,line.first);                                            // weight factor
  1779.         dist     = (((d2/td) * ratioTop) + ((1 - d2/td) * ratioBottom)) * d3;// distance along bisect line
  1780.         
  1781.         nPt    = CalculateLocation(&line,d3,dist);                                        // get point location
  1782.         HUnlock((Handle) this);
  1783.         nPoint = tRow->AddPointAt(column,nPt,((TGeomView *) fGeomView)->fMagnify);// add the point
  1784.         }
  1785.     return tRow;
  1786.     }
  1787.  
  1788. // --------------------------------------------------------------------------------------------------
  1789. //    TPointMatrix    :    GetColumnLength
  1790. //        Finds the total cumulative length of a column
  1791. // --------------------------------------------------------------------------------------------------
  1792. short TPointMatrix::GetColumnLength(short column)
  1793.     {
  1794.     extended total;
  1795.     Point t1, t2;
  1796.     short i;
  1797.     
  1798.     total = 0;
  1799.     t1 = ((TPoint *) ((TRow *) this->First())->At(column))->fStart;
  1800.     for (i = 2; i <= (short) fSize; i++)
  1801.         {
  1802.         t2 = ((TPoint *) ((TRow *) this->At(i))->At(column))->fStart;
  1803.         total += CalculateDistance(t1,t2);
  1804.         t1 = t2;
  1805.         }
  1806.     
  1807.     return total;
  1808.     }
  1809.     
  1810. // --------------------------------------------------------------------------------------------------
  1811. //    TPointMatrix    :    MovePoints
  1812. //        moves a row or column of points
  1813. // --------------------------------------------------------------------------------------------------
  1814. void TPointMatrix::MovePoints(Point temp, extended xlength)
  1815.     {
  1816.     TBoundry *    side;
  1817.     
  1818.     side = (TBoundry*) ((TGeomView *) fGeomView)->fSSide;
  1819.     if (side->GetSide() == cRight || side->GetSide() == cLeft)
  1820.         this->MoveRow(temp,xlength);
  1821.     else
  1822.         this->MoveColumn(temp,xlength);
  1823.     }
  1824.     
  1825. // --------------------------------------------------------------------------------------------------
  1826. //    TPointMatrix    :    MoveRow
  1827. //        moves a row or column of points
  1828. // --------------------------------------------------------------------------------------------------
  1829. void TPointMatrix::MoveRow(Point temp, extended rowLength)
  1830.     {
  1831.     TRow        * tRow;
  1832.     TPoint        * tr;
  1833.     Point        tPt, oPt;
  1834.     extended    ratio, l, aRatio;
  1835.     short        changeX, changeY;
  1836.     extended    x, y;
  1837.     short        column;
  1838.     
  1839.     tRow    = (TRow *) this->At(fRow);
  1840.     
  1841.     l = 0.0;
  1842.     
  1843.     PenMode(srcXor);
  1844.     if (fBoundry == cRight)
  1845.         oPt = ((TPoint *) tRow->Last())->fStart;
  1846.     else
  1847.         oPt     = ((TPoint *) tRow->First())->fStart;
  1848.     changeX = temp.h - oPt.h;
  1849.     changeY = temp.v - oPt.v;
  1850.         
  1851.     oPt     = ((TPoint *) tRow->First())->fStart;
  1852.     for (column = 2; column < (short) tRow->fSize; column++)
  1853.         {
  1854.         tr    = (TPoint *) tRow->At(column);
  1855.         tPt = tr->fStart;
  1856.             
  1857.         l += CalculateDistance(oPt,tPt);                                                // distance from boundry
  1858.         ratio = l / rowLength;                                                                // ratio for this point
  1859.  
  1860.         if (fBoundry == cLeft)
  1861.             aRatio = 1 - ratio;
  1862.         else
  1863.             aRatio = ratio;
  1864.         
  1865.         x = tPt.h +  (aRatio*changeX)+.5;                                                // store x
  1866.         y = tPt.v +  (aRatio*changeY)+.5;                                                // store y
  1867.             
  1868.         if (fShown)
  1869.             tr->DrawHold();
  1870.  
  1871.         tr->SetHold((short) y, (short) x);
  1872.  
  1873.         if (fShown)
  1874.             tr->DrawHold();
  1875.         oPt = tPt;
  1876.         }
  1877.     }
  1878.  
  1879. // --------------------------------------------------------------------------------------------------
  1880. //    TPointMatrix    :    MoveColumn
  1881. //        moves a row or column of points
  1882. // --------------------------------------------------------------------------------------------------
  1883. void TPointMatrix::MoveColumn(Point temp, extended colLength)
  1884.     {
  1885.     TPoint        *    tr;
  1886.     Point        tPt, oPt;
  1887.     extended    ratio, l, aRatio;
  1888.     short        changeX, changeY;
  1889.     extended    x, y;
  1890.     short        row;
  1891.     
  1892.     l = 0.0;
  1893.     
  1894.     PenMode(srcXor);
  1895.     if (fBoundry == cBottom)
  1896.         oPt = ((TPoint *) ((TRow *) this->Last())->At(fColumn))->fStart;
  1897.     else
  1898.         oPt     = ((TPoint *) ((TRow *) this->First())->At(fColumn))->fStart;
  1899.     changeX = temp.h - oPt.h;
  1900.     changeY = temp.v - oPt.v;
  1901.         
  1902.     oPt     = ((TPoint *) ((TRow *) this->First())->At(fColumn))->fStart;
  1903.     for (row = 2; row < (short) fSize; row++)
  1904.         {
  1905.         tr    = (TPoint *) ((TRow *) this->At(row))->At(fColumn);
  1906.         tPt = tr->fStart;
  1907.             
  1908.         l += CalculateDistance(oPt,tPt);                                                // distance from boundry
  1909.         ratio = l / colLength;                                                                // ratio for this point
  1910.  
  1911.         if (fBoundry == cTop)
  1912.             aRatio = 1 - ratio;
  1913.         else
  1914.             aRatio = ratio;
  1915.         
  1916.         x = tPt.h +  (aRatio*changeX)+.5;                                                // store x
  1917.         y = tPt.v +  (aRatio*changeY)+.5;                                                // store y
  1918.             
  1919.         if (fShown)
  1920.             tr->DrawHold();
  1921.         tr->SetHold((short) y, (short) x);
  1922.  
  1923.         if (fShown)
  1924.             tr->DrawHold();    
  1925.         oPt = tPt;
  1926.         }
  1927.     }
  1928.  
  1929. // --------------------------------------------------------------------------------------------------
  1930. //    TPointMatrix    :    RememberColumn
  1931. //        All points in that column remember yourself
  1932. // --------------------------------------------------------------------------------------------------
  1933. void TPointMatrix::RememberColumn(void)
  1934.     {
  1935.     TPoint  * t1;
  1936.     short i;
  1937.     
  1938.     for (i = 1; i <= (short) fSize; i++)
  1939.         {
  1940.         t1 = (TPoint *) ((TRow *) this->At(i))->At(fColumn);
  1941.         t1->RememberPoint();
  1942.         }
  1943.     
  1944.     return;
  1945.     }
  1946.     
  1947. // --------------------------------------------------------------------------------------------------
  1948. //    TPointMatrix    :    FixHold
  1949. //        moves a row or column of points
  1950. // --------------------------------------------------------------------------------------------------
  1951. void TPointMatrix::FixHold(void)
  1952.     {
  1953.     TBoundry *    side;
  1954.     
  1955.     side = (TBoundry*) ((TGeomView *) fGeomView)->fSSide;
  1956.     if (side->GetSide() == cRight || side->GetSide() == cLeft)
  1957.         {
  1958.         TRow * tRow;
  1959.         tRow = (TRow *) this->At(fRow);
  1960.         tRow->FixHold();
  1961.         }
  1962.     else
  1963.         this->FixHoldColumn(fColumn);
  1964.  
  1965.     return;        
  1966.     }
  1967.     
  1968. // --------------------------------------------------------------------------------------------------
  1969. //    TPointMatrix    :    FixHoldColumn
  1970. //        sets fStart = fHold (Done Dragging)
  1971. // --------------------------------------------------------------------------------------------------
  1972. void TPointMatrix::FixHoldColumn(short c)
  1973.     {
  1974.     short i;
  1975.     TPoint * tPt;
  1976.     for (i = 1; i <= (short) fSize; i++)
  1977.         {
  1978.         tPt = (TPoint *) ((TRow *) this->At(i))->At(c);
  1979.         tPt->FixHold();
  1980.         }
  1981.     }
  1982.     
  1983. // --------------------------------------------------------------------------------------------------
  1984. //    TPointMatrix    :    RetrieveAndFix2Hold
  1985. //        Retrieves the saved coordinates and places them in hold & fixes to fStart
  1986. // --------------------------------------------------------------------------------------------------
  1987. void TPointMatrix::RetrieveAndFix2Hold(void)
  1988.     {
  1989.     TBoundry *    side;
  1990.     
  1991.     side = (TBoundry*) ((TGeomView *) fGeomView)->fSSide;
  1992.     if (side->GetSide() == cRight || side->GetSide() == cLeft)
  1993.         {
  1994.         TRow * tRow;
  1995.         tRow = (TRow *) this->At(fRow);
  1996.         tRow->RetrieveAndFixRow();
  1997.         }
  1998.     else
  1999.         this->RetrieveAndFixColumn(fColumn);
  2000.  
  2001.     return;        
  2002.     }
  2003.     
  2004. // --------------------------------------------------------------------------------------------------
  2005. //    TPointMatrix    :    RetrieveAndFixColumn
  2006. //        Retrieves the saved coordinates and places them in hold & fixes to fStart
  2007. // --------------------------------------------------------------------------------------------------
  2008. void TPointMatrix::RetrieveAndFixColumn(short c)
  2009.     {
  2010.     short    i;
  2011.     TPoint    * tPt;
  2012.     Point    temp;
  2013.     
  2014.     for (i = 1; i <= (short) fSize; i++)
  2015.         {
  2016.         tPt = (TPoint *) ((TRow *) this->At(i))->At(c);
  2017.         temp = tPt->RetrievePoint();
  2018.         tPt->RememberPoint();
  2019.         tPt->SetStart(temp.v,temp.h);
  2020.         }
  2021.     }
  2022.     
  2023. // --------------------------------------------------------------------------------------------------
  2024. //    TPointMatrix    :    DrawHold
  2025. //        Draws the lines & points for the hold (called by TDragCommand)
  2026. // --------------------------------------------------------------------------------------------------
  2027. void TPointMatrix::DrawHold(Boolean dPoint)
  2028.     {
  2029.     short        side;
  2030.     TRow        * tRow;
  2031.     TPoint        *    above, * below, * left, * right, * tPt;
  2032.     short        i;
  2033.     
  2034.     fGeomView->Focus();
  2035.     side = ((TBoundry*) ((TGeomView *) fGeomView)->fSSide)->GetSide();
  2036.     if (side == cRight || side == cLeft)
  2037.         {
  2038. //    Draw left boundry    
  2039.         tRow    = (TRow *) this->At(fRow);
  2040.         above     = (TPoint *) ((TRow *) this->At(fRow-1))->First();
  2041.         below    = (TPoint *) ((TRow *) this->At(fRow+1))->First();
  2042.         tPt        = (TPoint *) tRow->First();
  2043.  
  2044.         if (tPt->fObsUpRight != NULL)
  2045.             ((TObstacle *) ((TPoint * ) tPt)->fObsUpRight)->Draw();
  2046.         if (tPt->fObsLwRight != NULL)
  2047.             ((TObstacle *) ((TPoint * ) tPt)->fObsLwRight)->Draw();
  2048.  
  2049.         if (tPt->fBaffAbove != NULL)
  2050.             ((TBaffle *) ((TPoint * ) tPt)->fBaffAbove)->Draw();
  2051.         if (tPt->fBaffBelow != NULL)
  2052.             ((TBaffle *) ((TPoint * ) tPt)->fBaffBelow)->Draw();
  2053.  
  2054.         if (side == cLeft)
  2055.             {
  2056.             tPt->DrawHoldLine(tPt->GetSectionType(),above->fTrans);
  2057.             below->DrawHoldLine(below->GetSectionType(),tPt->fTrans);
  2058.             }
  2059.  
  2060.         tPt->Draw();
  2061.         if (dPoint)
  2062.             {
  2063.             above->Draw();
  2064.             below->Draw();
  2065.             }
  2066.             
  2067. //    Draw Internal Points
  2068.         for (i = 2; i < (short) tRow->fSize; i++)
  2069.             {
  2070.             left = tPt;
  2071.             above     = (TPoint *) ((TRow *) this->At(fRow-1))->At(i);
  2072.             below    = (TPoint *) ((TRow *) this->At(fRow+1))->At(i);
  2073.             tPt        = (TPoint *) tRow->At(i);
  2074.             if (tPt->fObsUpRight != NULL)
  2075.                 ((TObstacle *) ((TPoint * ) tPt)->fObsUpRight)->Draw();
  2076.             if (tPt->fObsLwRight != NULL)
  2077.                 ((TObstacle *) ((TPoint * ) tPt)->fObsLwRight)->Draw();
  2078.  
  2079.             if (tPt->fBaffAbove != NULL)
  2080.                 ((TBaffle *) ((TPoint * ) tPt)->fBaffAbove)->Draw();
  2081.             if (tPt->fBaffBelow != NULL)
  2082.                 ((TBaffle *) ((TPoint * ) tPt)->fBaffBelow)->Draw();
  2083.             if (tPt->fBaffLeft != NULL)
  2084.                 ((TBaffle *) ((TPoint * ) tPt)->fBaffLeft)->Draw();
  2085.  
  2086.             tPt->DrawHoldLine(Grid,above->fTrans);
  2087.             tPt->DrawHoldLine(Grid,below->fTrans);
  2088.             tPt->DrawHoldLine(Grid,left->fTrans);
  2089.             if (dPoint)
  2090.                 {
  2091.                 tPt->Draw();
  2092.                 above->Draw();
  2093.                 below->Draw();
  2094.                 }
  2095.             }
  2096.             
  2097. //    Draw Right Boundry
  2098.         left         =    tPt;
  2099.         tPt        = (TPoint *) tRow->Last();
  2100.         above     = (TPoint *) ((TRow *) this->At(fRow-1))->Last();
  2101.         below    = (TPoint *) ((TRow *) this->At(fRow+1))->Last();
  2102.         tPt->DrawHoldLine(Grid,left->fTrans);
  2103.         
  2104.         if (tPt->fBaffAbove != NULL)
  2105.             ((TBaffle *) ((TPoint * ) tPt)->fBaffAbove)->Draw();
  2106.         if (tPt->fBaffBelow != NULL)
  2107.             ((TBaffle *) ((TPoint * ) tPt)->fBaffBelow)->Draw();
  2108.         if (tPt->fBaffLeft != NULL)
  2109.             ((TBaffle *) ((TPoint * ) tPt)->fBaffLeft)->Draw();
  2110.  
  2111.         if (side == cRight)
  2112.             {
  2113.             tPt->DrawHoldLine(tPt->GetSectionType(),above->fTrans);
  2114.             if (fRow == this->fSize-1)
  2115.                 below = (TPoint *) fRight->Last();
  2116.  
  2117.             below->DrawHoldLine(below->GetSectionType(),tPt->fTrans);
  2118.             }
  2119.         tPt->Draw();
  2120.         if (dPoint)
  2121.             {
  2122.             above->Draw();
  2123.             below->Draw();
  2124.             }
  2125.         }
  2126.     else
  2127.         {
  2128. //    Draw Top Boundry
  2129.         tRow     =     (TRow *) this->First();
  2130.         left        =    (TPoint *) tRow->At(fColumn-1);
  2131.         right        =    (TPoint *) tRow->At(fColumn+1);
  2132.         tPt        =    (TPoint *) tRow->At(fColumn);
  2133.         if (tPt->fObsLwLeft != NULL)
  2134.             ((TObstacle *) ((TPoint * ) tPt)->fObsLwLeft)->Draw();
  2135.         if (tPt->fObsLwRight != NULL)
  2136.             ((TObstacle *) ((TPoint * ) tPt)->fObsLwRight)->Draw();
  2137.  
  2138.         if (tPt->fBaffLeft != NULL)
  2139.             ((TBaffle *) ((TPoint * ) tPt)->fBaffLeft)->Draw();
  2140.         if (tPt->fBaffRight != NULL)
  2141.             ((TBaffle *) ((TPoint * ) tPt)->fBaffRight)->Draw();
  2142.  
  2143.         if (side == cTop)
  2144.             {
  2145.             tPt->DrawHoldLine(tPt->GetSectionType(),left->fTrans);
  2146.             right->DrawHoldLine(right->GetSectionType(),tPt->fTrans);
  2147.             }
  2148.  
  2149.         tPt->Draw();
  2150.         if (dPoint)
  2151.             {
  2152.             left->Draw();
  2153.             right->Draw();
  2154.             }
  2155.             
  2156. //    Draw Internal Points
  2157.         for (i = 2; i < (short) fSize; i++)
  2158.             {
  2159.             tRow    =    (TRow *) this->At(i);
  2160.             above    = tPt;
  2161.             left         = (TPoint *) tRow->At(fColumn-1);
  2162.             right        = (TPoint *) tRow->At(fColumn+1);
  2163.             tPt        = (TPoint *) tRow->At(fColumn);
  2164.             if (tPt->fObsLwLeft != NULL)
  2165.                 ((TObstacle *) ((TPoint * ) tPt)->fObsLwLeft)->Draw();
  2166.             if (tPt->fObsLwRight != NULL)
  2167.                 ((TObstacle *) ((TPoint * ) tPt)->fObsLwRight)->Draw();
  2168.  
  2169.             if (tPt->fBaffLeft != NULL)
  2170.                 ((TBaffle *) ((TPoint * ) tPt)->fBaffLeft)->Draw();
  2171.             if (tPt->fBaffRight != NULL)
  2172.                 ((TBaffle *) ((TPoint * ) tPt)->fBaffRight)->Draw();
  2173.             if (tPt->fBaffAbove != NULL)
  2174.                 ((TBaffle *) ((TPoint * ) tPt)->fBaffAbove)->Draw();
  2175.  
  2176.             tPt->DrawHoldLine(Grid,above->fTrans);
  2177.             tPt->DrawHoldLine(Grid,left->fTrans);
  2178.             tPt->DrawHoldLine(Grid,right->fTrans);
  2179.             if (dPoint)
  2180.                 {
  2181.                 left->Draw();
  2182.                 right->Draw();
  2183.                 tPt->Draw();
  2184.                 }
  2185.             }
  2186.             
  2187. //    Draw Bottom Boundry
  2188.         above    =    tPt;
  2189.         tRow    =    (TRow *) this->Last();
  2190.         left         =     (TPoint *) tRow->At(fColumn-1);
  2191.         right        =     (TPoint *) tRow->At(fColumn+1);
  2192.         tPt        =     (TPoint *) tRow->At(fColumn);
  2193.         tPt->DrawHoldLine(Grid,above->fTrans);
  2194.  
  2195.         if (tPt->fBaffLeft != NULL)
  2196.             ((TBaffle *) ((TPoint * ) tPt)->fBaffLeft)->Draw();
  2197.         if (tPt->fBaffRight != NULL)
  2198.             ((TBaffle *) ((TPoint * ) tPt)->fBaffRight)->Draw();
  2199.         if (tPt->fBaffAbove != NULL)
  2200.             ((TBaffle *) ((TPoint * ) tPt)->fBaffAbove)->Draw();
  2201.  
  2202.         if (side == cBottom)
  2203.             {
  2204.             tPt->DrawHoldLine(tPt->GetSectionType(),left->fTrans);
  2205.             right->DrawHoldLine(right->GetSectionType(),tPt->fTrans);
  2206.             }
  2207.         tPt->Draw();
  2208.         if (dPoint)
  2209.             {
  2210.             left->Draw();
  2211.             right->Draw();
  2212.             }
  2213.         }
  2214.     }
  2215.     
  2216. // *********************************************************************************
  2217. //    Delete Methods
  2218. //        these methods delete rows / columns from the mesh
  2219. // *********************************************************************************
  2220. // --------------------------------------------------------------------------------------------------
  2221. //    TPointMatrix    :    ObsBaffInLine .... 
  2222. //        delete the current row / column
  2223. // --------------------------------------------------------------------------------------------------
  2224. short TPointMatrix::ObsBaffInLine(TBoundry * side)
  2225.     {
  2226.     TPoint     *    tPt;
  2227.     short         x;
  2228.     
  2229.     fBoundry = side->GetSide();
  2230.     if (fBoundry == cTop || fBoundry == cBottom)
  2231.         {
  2232.         for (x = 1; x <= (short) this->fSize; x++)
  2233.             {
  2234.             tPt = (TPoint *) ((TRow *) this->At(x))->At(fColumn);
  2235.             if (tPt->fObsUpLeft != NULL || tPt->fObsLwLeft != NULL)
  2236.                 return 1;
  2237.         if (tPt->fBaffLeft != NULL)
  2238.                 return 2;
  2239.             }
  2240.         return 0;
  2241.         }
  2242.     TRow     *    tRow;
  2243.     tRow = (TRow *) this->At(fRow);
  2244.     for (x = 1; x <= (short) tRow->fSize; x++)
  2245.         {
  2246.         tPt = (TPoint *) tRow->At(x);
  2247.         if (tPt->fObsUpLeft != NULL || tPt->fObsUpRight != NULL)
  2248.             return 1;
  2249.         if (tPt->fBaffAbove != NULL)
  2250.             return 2;
  2251.         }
  2252.     return 0;
  2253.     }
  2254.     
  2255. // --------------------------------------------------------------------------------------------------
  2256. //    TPointMatrix    :    DeleteCurrent .... 
  2257. //        delete the current row / column
  2258. // --------------------------------------------------------------------------------------------------
  2259. TList * TPointMatrix::DeleteCurrent(TRow * side)
  2260.     {
  2261.     PointInfo    info;
  2262.     TPoint        * tPt, * t1, * t2;
  2263.     TRow        * tRow;
  2264.     Point        last, temp;
  2265.     short        y;
  2266.     
  2267.     fGeomView->Focus();
  2268.     PenMode(srcXor);
  2269.     fBoundry = side->GetSide();
  2270.     if (fBoundry == cTop || fBoundry == cBottom)
  2271.         {
  2272.         info.above = NULL;
  2273.         aColumn->DeleteAll();
  2274.         
  2275.         tRow = (TRow *) this->First();
  2276.         tPt    = (TPoint *) fTop->At(fColumn);                                                            // get the points
  2277.         t1        = (TPoint *) fTop->At(fColumn-1);
  2278.         t2        = (TPoint *) fTop->At(fColumn+1);
  2279.         last.h = tPt->fTrans.h;
  2280.         last.v = tPt->fTrans.v;
  2281.         
  2282.         tPt->DrawSection(t1->fTrans);                                                                    // erase the segments
  2283.         t2->DrawSection(tPt->fTrans);
  2284.         t1->DrawSection(t2->fTrans);                                                                        // redraw the segments
  2285.         tPt->Draw();                                                                                                // erase the points
  2286.          
  2287.         fTop->Delete(tPt);                                                                                        // delete from top list
  2288.         tRow->Delete(tPt);                                                                                        // delete from top row
  2289.         aColumn->InsertLast(tPt);                                                                            // put in hold list
  2290.         if (fBoundry == cTop)
  2291.             {
  2292.             temp = tPt->RetrievePoint();
  2293.             tPt->SetStart(temp.v,temp.h);
  2294.             }
  2295.     
  2296.         for (y = 2; y <= (short) this->fSize; y++)                                                        // all points in the column
  2297.             {
  2298.             tRow    =    (TRow *) this->At(y);
  2299.             tPt    = (TPoint *) tRow->At(fColumn);                                                        // get the points
  2300.             t1        = (TPoint *) tRow->At(fColumn-1);
  2301.             t2        = (TPoint *) tRow->At(fColumn+1);
  2302.             tPt->Draw();                                                                                            // erase the points
  2303.              
  2304.             if (y == (short) this->fSize)                                                                        // bottom boundry
  2305.                 {
  2306.                 tPt->DrawSection(t1->fTrans);                                                                // erase the segments
  2307.                 t2->DrawSection(tPt->fTrans);
  2308.                 if (fShown)
  2309.                     tPt->DrawGrid(last);                                                                        // erase the grid
  2310.  
  2311.                 t1->DrawSection(t2->fTrans);                                                                // redraw the segments
  2312.                 fBottom->Delete(tPt);                                                                            // delete from bottom list
  2313.                 if (fBoundry == cBottom)
  2314.                     {
  2315.                     temp = tPt->RetrievePoint();
  2316.                     tPt->SetStart(temp.v,temp.h);
  2317.                     }
  2318.                 }
  2319.             else if (fShown)
  2320.                 {
  2321.                 tPt->DrawGrid(t1->fTrans);                                                                    // erase the grid
  2322.                 t2->DrawGrid(tPt->fTrans);
  2323.                 tPt->DrawGrid(last);                                                                            // erase the grid
  2324.                 t1->DrawGrid(t2->fTrans);                                                                    // redraw the grid
  2325.                 }
  2326.             
  2327.             last.h = tPt->fTrans.h;
  2328.             last.v = tPt->fTrans.v;
  2329.             tRow->Delete(tPt);                                                                                    // delete the point from list
  2330.             aColumn->InsertLast(tPt);                                                                        // put in hold list
  2331.             }
  2332.         return aColumn;
  2333.         }
  2334.  
  2335.     short size;
  2336.  
  2337.     info.above = NULL;
  2338.     tRow    =    (TRow *) this->At(fRow);                                                            // the row
  2339.     tPt        = (TPoint *) tRow->Last();                                                                // get the points
  2340.     t1            = (TPoint *) ((TRow *) this->At(fRow-1))->Last();
  2341.     t2            = (TPoint *) ((TRow *) this->At(fRow+1))->Last();
  2342.     last.h     = tPt->fTrans.h;
  2343.     last.v     = tPt->fTrans.v;
  2344.  
  2345.     tPt->Draw();                                                                                                // erase the points
  2346.     tPt->DrawSection(t1->fTrans);                                                                        // erase the segment
  2347.     t2->DrawSection(tPt->fTrans);
  2348.     t1->DrawSection(t2->fTrans);                                                                        // redraw the segment
  2349.  
  2350.     fRight->Delete(tPt);
  2351.     if (fBoundry == cRight)
  2352.         {
  2353.         temp = tPt->RetrievePoint();
  2354.         tPt->SetStart(temp.v,temp.h);
  2355.         }
  2356.         
  2357.     size = (short) tRow->fSize;
  2358.     for (y = size-1; y > 0 ; y--)                                                                            // all points in the row
  2359.         {
  2360.         tPt    = (TPoint *) tRow->At(y);                                                                // get the points
  2361.         t1        = (TPoint *) ((TRow *) this->At(fRow-1))->At(y);
  2362.         t2        = (TPoint *) ((TRow *) this->At(fRow+1))->At(y);
  2363.         tPt->Draw();                                                                                            // erase the points
  2364.         
  2365.         if (y == 1)                                                                                                // on left or right boundry 
  2366.             {
  2367.             tPt->DrawSection(t1->fTrans);                                                                // erase the segment
  2368.             t2->DrawSection(tPt->fTrans);
  2369.             if (fShown)
  2370.                 tPt->DrawGrid(last);                                                                        // erase the grid
  2371.  
  2372.             t1->DrawSection(t2->fTrans);                                                                // redraw the segment
  2373.             fLeft->Delete(tPt);
  2374.             if (fBoundry == cLeft)
  2375.                 {
  2376.                 temp = tPt->RetrievePoint();
  2377.                 tPt->SetStart(temp.v,temp.h);
  2378.                 }
  2379.             }
  2380.         else if (fShown)
  2381.             {
  2382.             tPt->DrawGrid(t1->fTrans);                                                                    // erase the grid
  2383.             t2->DrawGrid(tPt->fTrans);
  2384.             tPt->DrawGrid(last);                                                                            // erase the grid
  2385.             t1->DrawGrid(t2->fTrans);                                                                    // redraw the grid
  2386.             }
  2387.         last.h = tPt->fTrans.h;
  2388.         last.v = tPt->fTrans.v;
  2389.         }
  2390.             
  2391.     this->Delete(tRow);                                                                                        // delete row from matrix
  2392.     return (TList *) tRow;
  2393.     }
  2394.             
  2395. // --------------------------------------------------------------------------------------------------
  2396. //    TPointMatrix    :    AddLine .... 
  2397. //        delete the current row / column
  2398. // --------------------------------------------------------------------------------------------------
  2399. TPoint * TPointMatrix::AddLine(TList * tList,TRow * side, short row, short column)
  2400.     {
  2401.     PointInfo    info, bInfo;
  2402.     TPoint        * tPt, * t1, * t2;
  2403.     TRow         * tRow;
  2404.     Point        last;
  2405.     short        y;
  2406.     
  2407.     fGeomView->Focus();
  2408.     PenMode(srcXor);
  2409.     fBoundry    = side->GetSide();
  2410.     fRow         = row;
  2411.     fColumn    = column;
  2412.     if (fBoundry == cTop || fBoundry == cBottom)
  2413.         {
  2414.         tRow = (TRow *) this->First();
  2415.         tPt    = (TPoint *) tList->First();        
  2416.         t1        = (TPoint *) fTop->At(fColumn-1);
  2417.         t2        = (TPoint *) fTop->At(fColumn);
  2418.         last.h = tPt->fTrans.h;
  2419.         last.v = tPt->fTrans.v;
  2420.         
  2421.         t2->DrawSection(t1->fTrans);                                                                        // erase section
  2422.         t2->DrawSection(tPt->fTrans);                                                                        // redraw section
  2423.         tPt->DrawSection(t1->fTrans);                                                                        // redraw section
  2424.         tPt->Draw();                                                                                                // redraw point
  2425.                     
  2426.         fTop->InsertBefore(fColumn,tPt);                                                                    // Add to top list
  2427.         tRow->InsertBefore(fColumn,tPt);                                                                // Add to top row
  2428.  
  2429.         for (y = 2; y <= (short) this->fSize; y++)                                                        // all points in the column
  2430.             {
  2431.             tRow    =    (TRow *) this->At(y);
  2432.             tPt    = (TPoint *) tList->At(y);                                                                // get the points
  2433.             t1        = (TPoint *) tRow->At(fColumn-1);
  2434.             t2        = (TPoint *) tRow->At(fColumn);
  2435.             
  2436.             if (y == (short) this->fSize)                                                                        // bottom boundry
  2437.                 {
  2438.                 t2->DrawSection(t1->fTrans);                                                                // erase section
  2439.                 fBottom->InsertBefore(fColumn,tPt);                                                    // Add to top list
  2440.                 t2->DrawSection(tPt->fTrans);                                                                // redraw section
  2441.                 if (fShown)
  2442.                     tPt->DrawGrid(last);                                                                        // erase the grid    
  2443.                 tPt->DrawSection(t1->fTrans);                                                                // redraw section
  2444.                 }
  2445.             else if (fShown)
  2446.                 {
  2447.                 t2->DrawGrid(t1->fTrans);                                                                    // erase section
  2448.                 tPt->DrawGrid(t1->fTrans);                                                                    // erase the grid
  2449.                 tPt->DrawGrid(last);                                                                            // erase the grid    
  2450.                 t2->DrawGrid(tPt->fTrans);                
  2451.                 }
  2452.             
  2453.             tRow->InsertBefore(fColumn,tPt);                                                            // Add to top row
  2454.             tPt->Draw();                                                            // redraw point
  2455.             last.h = tPt->fTrans.h;
  2456.             last.v = tPt->fTrans.v;
  2457.             }
  2458.         if (fBoundry == cTop)
  2459.             return (TPoint *) tList->First();
  2460.         else
  2461.             return (TPoint *) tList->Last();
  2462.         }
  2463.  
  2464.     short size;
  2465.     
  2466.     info.above     =    NULL;
  2467.     bInfo.above    =    NULL;
  2468.     tPt    = (TPoint *) tList->Last();                                                                    // get the points
  2469.     t1        = (TPoint *) ((TRow *) this->At(fRow-1))->Last();
  2470.     t2        = (TPoint *) ((TRow *) this->At(fRow))->Last();
  2471.     last.h = tPt->fTrans.h;
  2472.     last.v = tPt->fTrans.v;
  2473.  
  2474.     t1->DrawSection(t2->fTrans);                                                                        // erase section
  2475.     tPt->DrawSection(t1->fTrans);                                                                        // redraw the segment
  2476.     t2->DrawSection(tPt->fTrans);
  2477.     tPt->Draw();                                                                                                // redraw the point
  2478.  
  2479.     fRight->InsertBefore(fRow,tPt);
  2480.         
  2481.     size = (short) tList->fSize;
  2482.     for (y = size-1; y > 0 ; y--)                                                                            // all points in the row
  2483.         {
  2484.         tPt    = (TPoint *) tList->At(y);                                                                // get the points
  2485.         t1        = (TPoint *) ((TRow *) this->At(fRow-1))->At(y);
  2486.         t2        = (TPoint *) ((TRow *) this->At(fRow))->At(y);
  2487.  
  2488.         if (y == 1)                                                                                                // on left or right boundry 
  2489.             {
  2490.             t1->DrawSection(t2->fTrans);                                                                // erase the segment
  2491.             tPt->DrawSection(t1->fTrans);                                                                // erase the segment
  2492.             t2->DrawSection(tPt->fTrans);
  2493.             if (fShown)
  2494.                 tPt->DrawGrid(last);                                                                        // erase the grid
  2495.             fLeft->InsertBefore(fRow,tPt);
  2496.             }
  2497.         else if (fShown)
  2498.             {
  2499.             t1->DrawGrid(t2->fTrans);                                                                    // erase the grid
  2500.             tPt->DrawGrid(t1->fTrans);                                                                    // redraw the grid
  2501.             tPt->DrawGrid(last);                                                                            // erase the grid
  2502.             t2->DrawGrid(tPt->fTrans);
  2503.             }
  2504.  
  2505.         tPt->Draw();                                                                                            // redraw the point
  2506.         last.h = tPt->fTrans.h;
  2507.         last.v = tPt->fTrans.v;
  2508.         }
  2509.             
  2510.     this->InsertBefore(fRow,tList);                                                                    // add row to matrix
  2511.     if (fBoundry == cLeft)
  2512.         return (TPoint *) tList->First();
  2513.     else
  2514.         return (TPoint *) tList->Last();
  2515.     }            
  2516.     
  2517. // **********************************************************************
  2518. // --------------------------------------------------------------------------------------------------
  2519. //    TPointMatrix    :    WriteGrid
  2520. //        creates a column of grid points
  2521. // --------------------------------------------------------------------------------------------------
  2522. void TPointMatrix::WriteGrid(TOutput * output, short aRefNum, short export)
  2523.     {
  2524.     short    xx, yy, i;
  2525.     TPoint    * tPt;
  2526.     char     string[80];
  2527.     realPt    num;
  2528.     
  2529.     yy = 1;
  2530.     for (xx =1; xx <= (short) fTop->fSize; xx++)
  2531.         {        
  2532.         for (yy = (short) fSize; yy > 0; yy--)
  2533.             {
  2534.             tPt = (TPoint *) ((TRow *) this->At(yy))->At(xx);                // get point
  2535.             
  2536.             if (export == 1)
  2537.                 {
  2538.                 i = sprintf(string,"%d ",tPt->fStart.h);
  2539.                 i += sprintf(string+i,"%d\n",tPt->fStart.v);
  2540.                 }
  2541.             else
  2542.                 {
  2543.                 HLock((Handle) this);
  2544.                 ((TCFDFrontDocument *) fDocument)->ViewToReal(tPt->fStart,&num);
  2545.                 HUnlock((Handle) this);
  2546.                 i = sprintf(string,"%f ",num.x);                                            // x coordinate
  2547.                 i += sprintf(string+i,"%f",num.y);                                        // y coordinate
  2548.                 if (export == 2)
  2549.                     sprintf(string+i,"/\n");
  2550.                 else
  2551.                     sprintf(string+i,"/");
  2552.                 }
  2553.             output->Write(aRefNum,string);
  2554.             }
  2555.         }
  2556.     }
  2557.  
  2558. // --------------------------------------------------------------------------------------------------
  2559. //    TPointMatrix    :    WriteGrid
  2560. //        creates a column of grid points
  2561. // --------------------------------------------------------------------------------------------------
  2562. void TPointMatrix::WriteBaffles(Boolean vert, TOutput * output, short aRefNum)
  2563.     {
  2564.     short    xx, yy, i;
  2565.     TPoint    * tPt;
  2566.     char     string[80], sEnd[4];
  2567.  
  2568.     ((TCFDFrontDocument *) fDocument)->AddTerminator(sEnd);
  2569.     
  2570.     for (xx =1; xx <= (short) fTop->fSize; xx++)
  2571.         {        
  2572.         for (yy = (short) fSize; yy > 0; yy--)
  2573.             {
  2574.             tPt = (TPoint *) ((TRow *) this->At(yy))->At(xx);                    // get point
  2575.             
  2576.             if (vert && tPt->fBaffAbove != NULL)
  2577.                 {
  2578.                 i = sprintf(string,"%d ",xx-1);                                            // x coordinate
  2579.                 i += sprintf(string+i,"%d ",(fSize - yy + 1));                        // y coordinate
  2580.                 i += sprintf(string+i,"%d",(fSize - yy + 1));                        // y coordinate
  2581.                 sprintf(string+i,"%s",sEnd);                                                // model
  2582.                 output->Write(aRefNum,string);
  2583.                 }
  2584.             else if (!vert && tPt->fBaffLeft != NULL)
  2585.                 {
  2586.                 i = sprintf(string,"%d ",(fSize - yy));                                    // y coordinate
  2587.                 i += sprintf(string+i,"%d ",xx-1);                                        // x coordinate
  2588.                 i += sprintf(string+i,"%d",xx-1);                                        // x coordinate
  2589.                 sprintf(string+i,"%s",sEnd);                                                // model
  2590.                 output->Write(aRefNum,string);
  2591.                 }
  2592.             }
  2593.         }
  2594.     }
  2595.  
  2596. // --------------------------------------------------------------------------------------------------
  2597. //    TPointMatrix    :    WriteObstacles
  2598. //        writes obstacles
  2599. // --------------------------------------------------------------------------------------------------
  2600. void TPointMatrix::WriteObstacles(TOutput * output, short aRefNum)
  2601.     {
  2602.     short    xx, yy, i;
  2603.     TPoint    * tPt;
  2604.     char     string[80], sEnd[4];
  2605.  
  2606.     ((TCFDFrontDocument *) fDocument)->AddTerminator(sEnd);
  2607.         
  2608.     for (xx =1; xx <= (short) fTop->fSize; xx++)
  2609.         {        
  2610.         for (yy = (short) fSize; yy > 0; yy--)
  2611.             {
  2612.             tPt = (TPoint *) ((TRow *) this->At(yy))->At(xx);                    // get point
  2613.             
  2614.             if (tPt->fObsLwLeft != NULL)
  2615.                 {
  2616.                 i = sprintf(string,"%d ",xx-1);                                            // x coordinate
  2617.                 i += sprintf(string+i,"%d ",xx-1);                                        // x coordinate
  2618.                 i += sprintf(string+i,"%d ",(fSize - yy));                                // y coordinate
  2619.                 i += sprintf(string+i,"%d",(fSize - yy));                                // y coordinate
  2620.                 sprintf(string+i,"%s",sEnd);                                                // model
  2621.                 output->Write(aRefNum,string);
  2622.                 }
  2623.             }
  2624.         }
  2625.     }
  2626.  
  2627. // **********************************************************************
  2628. // --------------------------------------------------------------------------------------------------
  2629. //    TPointMatrix    :    ReadSegment
  2630. //        reads the segment information from the file
  2631. // --------------------------------------------------------------------------------------------------
  2632. Boolean TPointMatrix::ReadSegment(short side, short aRefNum, char * buff, short total)
  2633.     {
  2634.     char             s[80];
  2635.     short            num, x, y, type, tEnd, tCell;
  2636.     TRow            * tRow;
  2637.     TGPoint        * gPt;
  2638.     TSegPoint        * sPt;
  2639.     WallRecord    data;
  2640.     
  2641.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // ns        -    number of segments
  2642.     num = atoi(s);
  2643.     
  2644.     switch (side)
  2645.         {
  2646.         case cTop:
  2647.             tRow = fTop;
  2648.             break;
  2649.         case cBottom:
  2650.             tRow = fBottom;
  2651.             break;
  2652.         case cLeft:
  2653.             tRow = fLeft;
  2654.             break;
  2655.         case cRight:
  2656.             tRow = fRight;
  2657.             break;
  2658.         }
  2659.             
  2660.     x = y = 1;
  2661.     tEnd = 0;
  2662.     while (x <= total)
  2663.         {
  2664.         if (x > tEnd && y <= num)
  2665.             {
  2666.             ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // kb        -    boundry type
  2667.             type = atoi(s);
  2668.  
  2669.             ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // jf        -    starting grid cell
  2670.             tCell = atoi(s);
  2671.             ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // jl            -    ending grid cell
  2672.             tEnd = atoi(s);
  2673.         
  2674.             HLock((Handle) this);
  2675.             this->ReadData(&data, aRefNum, buff);                                                            // jl            -    ending grid cell
  2676.             HUnlock((Handle) this);
  2677.             
  2678.             if (side == cLeft || side == cRight)
  2679.                 {
  2680.                 if (x == 1)
  2681.                     {
  2682.                     sPt = (TSegPoint *) tRow->Last();                                                        // get the point
  2683.                     sPt->SetData(data);                                                                                // store the data
  2684.                     sPt->SetSectionType(type);
  2685.                     }
  2686.                 else
  2687.                     {
  2688.                     sPt = new TSegPoint;
  2689.                     if (sPt == NULL)
  2690.                         return false;
  2691.                     sPt->IPoint(0,0,type,((TGeomView *) fGeomView)->fMagnify);
  2692.                     sPt->SetData(data);
  2693.                     tRow->InsertBefore(2, (TObject *) sPt);
  2694.                     }
  2695.                 while (x < tEnd)
  2696.                     {
  2697.                     gPt = new TGPoint;
  2698.                     if (gPt == NULL)
  2699.                         return false;
  2700.                     gPt->IPoint(0,0,type,((TGeomView *) fGeomView)->fMagnify);
  2701.                     tRow->InsertBefore(2, (TObject *) gPt);
  2702.                     x++;
  2703.                     }                
  2704.                 }
  2705.             else
  2706.                 {
  2707.                 while (x < tEnd)
  2708.                     {
  2709.                     gPt = new TGPoint;
  2710.                     if (gPt == NULL)
  2711.                         return false;
  2712.                     gPt->IPoint(0,0,type,((TGeomView *) fGeomView)->fMagnify);
  2713.                     tRow->InsertBefore(((short) tRow->fSize), (TObject *) gPt);
  2714.                     x++;
  2715.                     }
  2716.                 if (x == total-1 && (side == cTop || side == cBottom))
  2717.                     {
  2718.                     sPt = (TSegPoint *) tRow->Last();                                                            // get the point
  2719.                     sPt->SetData(data);                                                                                    // store the data
  2720.                     sPt->SetSectionType(type);
  2721.                     }
  2722.                 else
  2723.                     {
  2724.                     sPt = new TSegPoint;
  2725.                     if (sPt == NULL)
  2726.                         return false;
  2727.                     sPt->IPoint(0,0,type,((TGeomView *) fGeomView)->fMagnify);
  2728.                     sPt->SetData(data);
  2729.                     tRow->InsertBefore(((short) tRow->fSize), (TObject *) sPt);
  2730.                     }
  2731.                 }
  2732.             y++;
  2733.             }
  2734.         x++;
  2735.         }
  2736.     }
  2737.                 
  2738. // --------------------------------------------------------------------------------------------------
  2739. //    TPointMatrix    :    ReadData
  2740. //        reads the segment information from the file
  2741. // --------------------------------------------------------------------------------------------------
  2742. void TPointMatrix::ReadData(WallRecord * data, short aRefNum, char * buff)
  2743.     {
  2744.     char             s[80];
  2745.  
  2746.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // u        -    u velocity
  2747.     data->u = atof(s);
  2748.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // v        -    v velocity
  2749.     data->v = atof(s);
  2750.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // w    -    w velocity
  2751.     data->w = atof(s);
  2752.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // visc    -    viscosity
  2753.     data->visc = atof(s);
  2754.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // t        -    temperature
  2755.     data->temp = atof(s);
  2756.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // rh    -    density
  2757.     data->density = atof(s);
  2758.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // f        -    mixture fraction
  2759.     data->mixfrac = atof(s);
  2760.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // g        -    concentration fraction
  2761.     data->concfrac = atof(s);
  2762.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // tk    -    kinetic energy
  2763.     data->kenergy = atof(s);
  2764.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // td    -    dissipation
  2765.     data->dissip = atof(s);
  2766.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // fu    -    fuel fraction
  2767.     data->fuelfrac = atof(s);
  2768.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // co2    -    always 0 - not stored
  2769.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // h2o    -    always 0 - not stored
  2770.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // o2    -    always 0 - not stored
  2771.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // wm    -    always 0 - not stored
  2772.     }
  2773.         
  2774. // --------------------------------------------------------------------------------------------------
  2775. //    TPointMatrix    :    FillGrid
  2776. //        creates the interior grid points
  2777. //        used after segment data points have been read from a file
  2778. // --------------------------------------------------------------------------------------------------
  2779. Boolean TPointMatrix::FillGrid(short row, short column)
  2780.     {
  2781.     short tCol, tRow;
  2782.     
  2783.     tCol        = (short) fTop->fSize;
  2784.     tRow    = (short) fLeft->fSize;
  2785.         
  2786.     if (tRow != row || tCol != column)
  2787.         {
  2788.         SysBeep (3);
  2789.         TWarning * tWarning;
  2790.         TWindow    * aWindow;
  2791.         
  2792.         aWindow = NewTemplateWindow(kWarnMe, fDocument);
  2793.         tWarning = (TWarning *) aWindow->FindSubView('WARN');
  2794.         tWarning->IWarning(6,NULL);
  2795.         tWarning->ShowWarning();
  2796.         Failure(0,0);
  2797.         }
  2798.     
  2799.     short x, y;
  2800.     TPoint        * tPt1, * tPt2;
  2801.     TGridPoint     * gPt;
  2802.     TRow            * gRow;
  2803.     
  2804.     gRow = (TRow *) this->First();                                                                        // create top
  2805.     for (y = tCol-1; y > 1; y--)
  2806.         {
  2807.         tPt1 = (TPoint *) fTop->At(y);                                                                        // get point
  2808.         gRow->InsertBefore(2, (TObject *) tPt1);                                                    // insert point
  2809.         }
  2810.     gRow = (TRow *) this->Last();                                                                            // create bottom
  2811.     for (y = tCol-1; y > 1; y--)
  2812.         {
  2813.         tPt1 = (TPoint *) fBottom->At(y);                                                                // get point
  2814.         gRow->InsertBefore(2,(TObject *) tPt1);                                                        // insert point
  2815.         }
  2816.         
  2817.     for (y = tRow-1; y > 1; y--)
  2818.         {
  2819.         tPt1 = (TPoint *) fLeft->At(y);
  2820.         tPt2 = (TPoint *) fRight->At(y);
  2821.         gRow = new TRow;
  2822.             FailNIL(gRow);                                                                                            // LAM
  2823.         gRow->IRow(tPt1,tPt2);                                                                                // initialize the row
  2824.         this->InsertBefore(2, (TObject *) gRow);                                                        // add the row
  2825.         for (x = 2; x < tCol; x++)
  2826.             {
  2827.             gPt = new TGridPoint;
  2828.                 FailNIL(gPt);                                                                                            // LAM
  2829.             gPt->IPoint(0,0,Grid,((TGeomView *) fGeomView)->fMagnify);                // initialize the point
  2830.             gRow->InsertBefore(2, (TObject *) gPt);                                                    // add the point
  2831.             }
  2832.         }
  2833.     return true;
  2834.     }
  2835.                         
  2836. // --------------------------------------------------------------------------------------------------
  2837. //    TPointMatrix    :    ReadObstructions
  2838. //        reads the obstacle & baffle information
  2839. // --------------------------------------------------------------------------------------------------
  2840. void TPointMatrix::ReadObstructions(short aRefNum, char * buff)
  2841.     {
  2842.     PointInfo    info;
  2843.     TBaffle        * tBaffle;
  2844.     TObstacle    * tObstacle;
  2845.     char         s[80];
  2846.     short        nxbaf, nybaf, nobs, i;
  2847.     short        xstart, xend, ystart, yend;
  2848.     
  2849.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // nxbaf    -    # vertical baffles
  2850.     nxbaf = atoi(s);
  2851.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // nybaf    -    # horizontal baffles
  2852.     nybaf = atoi(s);
  2853.     ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                    // nobs    -    # obstacles
  2854.     nobs  = atoi(s);
  2855.     
  2856.     info.left = NULL;
  2857.     info.right = NULL;                                                                                                // null non-used points
  2858.     for (i = 1; i <= nxbaf; i++)                                                                                // vertical baffles
  2859.         {
  2860.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // ifc        -    xstart cell
  2861.         xstart = atoi(s) + 1;
  2862.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // jfc        -    ystart cell
  2863.         ystart = (short) this->fSize - atoi(s);
  2864.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // jlc        -     yend cell
  2865.         yend = (short) this->fSize - atoi(s) + 1;
  2866.         
  2867.         info.above = (TPoint *) ((TRow *) this->At(ystart))->At(xstart);                // get baffle points
  2868.         info.below = (TPoint *) ((TRow *) this->At(yend))->At(xstart);
  2869.         
  2870.         tBaffle = new TBaffle;
  2871.             FailNIL (tBaffle);                                                                                        // LAM
  2872.         HLock((Handle) this);
  2873.         tBaffle->IBaffle(&info,1);                                                                                // initialize vertical baffle
  2874.         HUnlock((Handle) this);
  2875.         }
  2876.         
  2877.     info.above = info.below = NULL;                                                                            // null non-used points
  2878.     for (i = 1; i <= nybaf; i++)                                                                                // horizontal baffles
  2879.         {
  2880.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // ifc        -    xstart cell
  2881.         ystart    = (short) this->fSize - atoi(s);
  2882.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // jfc        -    ystart cell
  2883.         xstart    = atoi(s);
  2884.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // jlc        -     yend cell
  2885.         xend        = atoi(s) + 1;
  2886.         
  2887.         info.left    = (TPoint *) ((TRow *) this->At(ystart))->At(xstart);                    // get baffle points
  2888.         info.right    = (TPoint *) ((TRow *) this->At(ystart))->At(xend);
  2889.         
  2890.         tBaffle = new TBaffle;
  2891.             FailNIL (tBaffle);                                                                                        // LAM
  2892.         HLock((Handle) this);
  2893.         tBaffle->IBaffle(&info,2);                                                                                // initialize vertical baffle
  2894.         HUnlock((Handle) this);
  2895.         }
  2896.         
  2897.     info.right = NULL;                                                                                                // null non-used points
  2898.     for (i = 1; i <= nobs; i++)                                                                                    // obstacles
  2899.         {
  2900.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // ifc        -    xstart cell
  2901.         xstart    = atoi(s);
  2902.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // jlc        -     yend cell
  2903.         xend        = atoi(s) + 1;
  2904.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // jfc        -    ystart cell
  2905.         ystart    = (short) this->fSize - atoi(s);
  2906.         ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);                // jlc        -     yend cell
  2907.         yend        = (short) this->fSize - atoi(s) + 1;
  2908.         
  2909.         info.oPt    = (TPoint *) ((TRow *) this->At(ystart))->At(xstart);                    // get obstacle points
  2910.         info.above    = (TPoint *) ((TRow *) this->At(ystart))->At(xend);
  2911.         info.left    = (TPoint *) ((TRow *) this->At(yend))->At(xstart);    
  2912.         info.below    = (TPoint *) ((TRow *) this->At(yend))->At(xend);
  2913.         
  2914.         tObstacle = new TObstacle;
  2915.             FailNIL (tObstacle);                                                                                        // LAM
  2916.         HLock((Handle) this);
  2917.         tObstacle->IObstacle(&info);                                                                                // initialize vertical baffle
  2918.         HUnlock((Handle) this);
  2919.         }
  2920.     return;
  2921.     }
  2922.     
  2923. // --------------------------------------------------------------------------------------------------
  2924. //    TPointMatrix    :    ReadGrid
  2925. //        read a column of grid points
  2926. // --------------------------------------------------------------------------------------------------
  2927. void TPointMatrix::ReadGrid(short aRefNum, char * buff)
  2928.     {
  2929.     short    xx, yy, x, y;
  2930.     TPoint    * tPt, * tPt1;
  2931.     char     s[80];
  2932.     
  2933. short t;
  2934.     
  2935.     for (xx =1; xx <= (short) fTop->fSize; xx++)
  2936.         {        
  2937.         for (yy = (short) fSize; yy > 0; yy--)
  2938.             {
  2939.             if (yy == 1)
  2940.                 t  = 1;
  2941.             ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);            // x coordinate
  2942.             x = atoi(s);
  2943.             ((TCFDFrontDocument *) fDocument)->ReadLine(aRefNum, buff, s);            // y coordinate
  2944.             y = atoi(s);
  2945.             
  2946.             tPt = (TPoint *) ((TRow *) this->At(yy))->At(xx);                                    // get point
  2947.             tPt->SetStart(y,x);
  2948.             }
  2949.         }
  2950.     tPt  = (TPoint *) fBottom->Last();
  2951.     tPt1 = (TPoint *) fRight->Last();
  2952.     tPt1->SetStart(tPt->fStart.v,tPt->fStart.h);
  2953.     }
  2954.  
  2955.